00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008
00009 union BmpColor
00010 {
00011 DWORD clr;
00012 struct {
00013 BYTE r, g, b, a;
00014 };
00015
00016 BmpColor (DWORD dw) {clr = dw;}
00017 BmpColor () {}
00018 };
00019
00020 BmpColor MixColor (BmpColor clr1, BmpColor clr2)
00021 {
00022 double alpha, notalpha;
00023 BmpColor res;
00024
00025 alpha = clr1.a / 255.0;
00026 notalpha = 1.0 - alpha;
00027
00028 res.r = BYTE (clr1.r*alpha + clr2.b*notalpha + 0.5);
00029 res.g = BYTE (clr1.g*alpha + clr2.g*notalpha + 0.5);
00030 res.b = BYTE (clr1.b*alpha + clr2.r*notalpha + 0.5);
00031 res.a = 0;
00032
00033 return res;
00034 }
00035
00036 void ConvertBmp32WithAlphaToBmp32WithoutAlpha (CBitmap& bmp, COLORREF clrBk)
00037 {
00038 int w, h;
00039
00040 BITMAP bm;
00041 bmp.GetBitmap (&bm);
00042
00043 h = bm.bmHeight;
00044 w = bm.bmWidth;
00045
00046 DWORD* pdwBmp32plusA = new DWORD [w*h];
00047 bmp.GetBitmapBits (w*h*4, pdwBmp32plusA);
00048
00049 DWORD* pdwBmp32 = new DWORD [w*h];
00050
00051 for (int i = 0; i < h; i++)
00052 {
00053 for (int k = 0; k < w; k++)
00054 {
00055 BmpColor clr = MixColor (pdwBmp32plusA [i*w+k], clrBk);
00056 pdwBmp32 [(h-1)*w - i*w + k] = clr.clr;
00057 }
00058 }
00059
00060 bmp.DeleteObject ();
00061
00062 HDC dc = GetDC (NULL);
00063 bmp.CreateCompatibleBitmap (CDC::FromHandle (dc), w, h);
00064
00065 BITMAPINFO bi;
00066 ZeroMemory (&bi, sizeof (bi));
00067 bi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
00068 bi.bmiHeader.biWidth = w;
00069 bi.bmiHeader.biHeight = h;
00070 bi.bmiHeader.biPlanes = 1;
00071 bi.bmiHeader.biCompression = BI_RGB;
00072
00073 bi.bmiHeader.biBitCount = 32;
00074 SetDIBits (dc, bmp, 0, h, pdwBmp32, &bi, DIB_RGB_COLORS);
00075
00076 delete [] pdwBmp32plusA;
00077 delete [] pdwBmp32;
00078 }
00079
00080 char _szAppDataFolder [MY_MAX_PATH] = "";
00081 bool _bNeedRecalcAppDataFolder = false;
00082
00083 void fsGetSystemAppDataFolder (LPSTR pszRes)
00084 {
00085 LPITEMIDLIST pidl = NULL;
00086 if (SUCCEEDED (SHGetSpecialFolderLocation (NULL, CSIDL_APPDATA, &pidl)))
00087 {
00088 SHGetPathFromIDList (pidl, pszRes);
00089 if (pszRes [lstrlen (pszRes)-1] != '\\')
00090 lstrcat (pszRes, "\\");
00091 IMallocPtr spMalloc;
00092 SHGetMalloc (&spMalloc);
00093 spMalloc->Free (pidl);
00094 }
00095 else
00096 {
00097 GetWindowsDirectory (pszRes, MAX_PATH);
00098 if (pszRes [3] != 0)
00099 lstrcat (pszRes, "\\");
00100 lstrcat (pszRes, "Application Data\\");
00101 }
00102 }
00103
00104 LPCSTR fsGetAppDataFolder ()
00105 {
00106 if (_bNeedRecalcAppDataFolder)
00107 {
00108 _bNeedRecalcAppDataFolder = false;
00109 *_szAppDataFolder = 0;
00110 }
00111
00112 if (*_szAppDataFolder)
00113 return _szAppDataFolder;
00114
00115 CString str = _App.DataFolder ();
00116 if (str.IsEmpty () == FALSE)
00117 {
00118 lstrcpy (_szAppDataFolder, str);
00119 if (_szAppDataFolder [lstrlen (_szAppDataFolder)-1] != '\\')
00120 lstrcat (_szAppDataFolder, "\\");
00121 return _szAppDataFolder;
00122 }
00123
00124 if (IS_PORTABLE_MODE)
00125 {
00126 lstrcpy (_szAppDataFolder, ((CFdmApp*)AfxGetApp ())->m_strAppPath);
00127 lstrcat (_szAppDataFolder, "Data\\");
00128 return _szAppDataFolder;
00129 }
00130
00131 fsGetSystemAppDataFolder (_szAppDataFolder);
00132 lstrcat (_szAppDataFolder, "Open Download Manager\\");
00133 return _szAppDataFolder;
00134 }
00135
00136 CString fsGetDataFilePath (LPCSTR pszFile)
00137 {
00138 fsGetAppDataFolder ();
00139
00140 CString strPath = _szAppDataFolder;
00141 strPath += pszFile;
00142
00143 fsBuildPathToFile (strPath);
00144
00145 if (strPath != pszFile)
00146 {
00147 if (GetFileAttributes (pszFile) != DWORD (-1) &&
00148 GetFileAttributes (strPath) == DWORD (-1))
00149 CopyFile (pszFile, strPath, TRUE);
00150 }
00151
00152 return strPath;
00153 }
00154
00155 extern CFdmApp theApp;
00156
00157 LPCSTR fsGetFumProgramFilesFolder ()
00158 {
00159 static char _szPath [MAX_PATH] = "";
00160 if (*_szPath == 0)
00161 {
00162 CRegKey key;
00163 DWORD dw = MAX_PATH;
00164 if (ERROR_SUCCESS == key.Open (HKEY_CURRENT_USER, "Software\\OpenDownloadManager.ORG\\Open Upload Manager"))
00165 key.QueryValue (_szPath, "Path", &dw);
00166
00167 if (*_szPath != 0)
00168 {
00169 CString str = _szPath;
00170 str += "fum.exe";
00171 if (GetFileAttributes (str) == DWORD (-1))
00172 *_szPath = 0;
00173 }
00174
00175 if (*_szPath == 0)
00176 {
00177 lstrcpy (_szPath, theApp.m_strAppPath);
00178 lstrcat (_szPath, "fum\\");
00179 }
00180 }
00181 return _szPath;
00182 }
00183
00184 extern CFdmApp theApp;
00185 CString vmsGetAppFolder ()
00186 {
00187 return theApp.m_strAppPath;
00188 }
00189
00190 void mfcSetForegroundWindow (CWnd *pwnd)
00191 {
00192 fsSetForegroundWindow (pwnd->m_hWnd);
00193 pwnd->SetForegroundWindow ();
00194 pwnd->BringWindowToTop ();
00195 }