//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include #include "gdiplus.h" #include "GlobalUnit.h" #include "MenuHookUnit.h" #include "SplashFormUnit.h" #include "MessageFormUnit.h" //--------------------------------------------------------------------------- using namespace Gdiplus; USEFORM("SplashFormUnit.cpp", SplashForm); USEFORM("MessageFormUnit.cpp", MessageForm); USEFORM("MainFormUnit.cpp", MainForm); //--------------------------------------------------------------------------- ULONG_PTR theGdiplusToken; GdiplusStartupInput theGdiplusStartupInput; HWND hWnd = NULL; HINSTANCE u_hMMDll = NULL, u_hMFDll = NULL, u_hCSDll = NULL, u_hQRDll = NULL; void InitUserPath() { SplashForm->ShowProgress( "配置用户路径..." ); String strAppPath = TPath::GetFullPath(ExtractFilePath(Application->ExeName)); g_strExecutePath = strAppPath.c_str(); TCHAR filePath[MAX_PATH]; SHGetSpecialFolderPath(NULL, filePath, CSIDL_LOCAL_APPDATA, TRUE); String strLocPath = filePath; strLocPath += L"\\iChangzuo"; if(!DirectoryExists( strLocPath, false)){ ForceDirectories( strLocPath ); } strLocPath += L"\\AccompanyCube\\"; g_strUserPath = strLocPath.c_str(); // g_strUserPath = strAppPath.c_str(); if(!DirectoryExists( strLocPath, false)){ ForceDirectories( strLocPath ); } if(!DirectoryExists( strLocPath + L"Help", false)){ ForceDirectories( strLocPath + L"Help" ); } if(!DirectoryExists( strLocPath + L"Header", false)){ ForceDirectories( strLocPath + L"Header" ); } String strSrc = strAppPath + L"Header\\default.jpg", strDest = strLocPath + L"Header\\default.jpg"; if( FileExists(strSrc, false) && !FileExists( strDest, false ) ){ CopyFile( strSrc.c_str(), strDest.c_str(), FALSE ); } strLocPath += L"Profile\\"; strAppPath += L"Profile\\"; bool bCover = false; if( DirectoryExists( strAppPath, false ) ){ if( !DirectoryExists( strLocPath, false) ){ ForceDirectories( strLocPath ); bCover = true; } } else{ return; } String strSubPathShort[3] = { "dt_eerp", "ml_bursa", "sf_lyres" }, strDefaultFile[3] = { "uflid.jst", "frm0000.lmd", "Lcyh00000.dhy" }; for( int i=0; i<3; i++ ){ String strOriPath = strAppPath + strSubPathShort[i], strSubPath = strLocPath + strSubPathShort[i]; if( DirectoryExists( strOriPath, false ) ){ if( !DirectoryExists( strSubPath, false ) ){ ForceDirectories( strSubPath ); bCover = true; } else{ String strExistFile = strOriPath + L"\\" + strDefaultFile[i], strNewFile = strSubPath + L"\\" + strDefaultFile[i]; HANDLE hOriFile = CreateFile( strExistFile.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); if( hOriFile && hOriFile!=INVALID_HANDLE_VALUE ){ HANDLE hNewFile = CreateFile( strNewFile.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if( hNewFile && hNewFile!=INVALID_HANDLE_VALUE ){ DWORD dwSizeOri = GetFileSize( hOriFile, NULL ), dwSizeNew = GetFileSize( hNewFile, NULL ); FILETIME ftModifyOri, ftModifyNew; GetFileTime( hOriFile, NULL, NULL, &ftModifyOri ); GetFileTime( hNewFile, NULL, NULL, &ftModifyNew ); if( dwSizeOri>dwSizeNew || CompareFileTime( &ftModifyOri, &ftModifyNew )>0 ) bCover = true; CloseHandle( hNewFile ); } else{ bCover = true; } CloseHandle( hOriFile ); } else{ return; } } } else{ return; } } TSearchRec sr; int iAttr = 0; for( int i=0; i<3; i++ ){ String strOriPath = strAppPath + strSubPathShort[i], strSubPath = strLocPath + strSubPathShort[i]; if (FindFirst(strOriPath + L"\\*.*", iAttr, sr) == 0) { do { String strExistFile = strOriPath + L"\\" + sr.Name, strNewFile = strSubPath + L"\\" + sr.Name; bool bCopy = true; HANDLE hOriFile = NULL; if( !sr.Name.Compare(strDefaultFile[i]) ){ bCopy = bCover; } else if( FileExists( strNewFile, false ) ){ HANDLE hOriFile = CreateFile( strExistFile.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); if( hOriFile && hOriFile!=INVALID_HANDLE_VALUE ){ HANDLE hNewFile = CreateFile( strNewFile.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if( hNewFile && hNewFile!=INVALID_HANDLE_VALUE ){ FILETIME ftModifyOri, ftModifyNew; GetFileTime( hOriFile, NULL, NULL, &ftModifyOri ); GetFileTime( hNewFile, NULL, NULL, &ftModifyNew ); CloseHandle( hNewFile ); if( CompareFileTime( &ftModifyNew, &ftModifyOri )>=0 ){ bCopy = false; } } CloseHandle( hOriFile ); } else{ bCopy = false; } } if( bCopy ) CopyFile( strExistFile.c_str(), strNewFile.c_str(), FALSE ); } while( FindNext(sr)==0 ); FindClose(sr); } } String strExistFile = strAppPath + L"Collect.dat"; if( FileExists( strExistFile ) ){ HANDLE hOriFile = CreateFile( strExistFile.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL ); if( hOriFile && hOriFile!=INVALID_HANDLE_VALUE ){ bool bCopy = true; String strNewFile = strLocPath + L"Collect.dat"; HANDLE hNewFile = CreateFile( strNewFile.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if( hNewFile && hNewFile!=INVALID_HANDLE_VALUE ){ FILETIME ftModifyOri, ftModifyNew; GetFileTime( hOriFile, NULL, NULL, &ftModifyOri ); GetFileTime( hNewFile, NULL, NULL, &ftModifyNew ); if( CompareFileTime( &ftModifyNew, &ftModifyOri )>=0 ) bCopy = false; CloseHandle( hNewFile ); } CloseHandle( hOriFile ); if( bCopy ) CopyFile( strExistFile.c_str(), strNewFile.c_str(), FALSE ); } } } int LoadDlls() { SplashForm->ShowProgress( "加载媒体模块..." ); u_hMMDll = LoadLibrary(L"MediaModule.dll");//LoadLibraryEx(L"MediaModule.dll", NULL, LOAD_WITH_ALTERED_SEARCH_PATH);// if( u_hMMDll==NULL ){ int err = GetLastError(); return 1; } else if( GetMMFunctions(u_hMMDll)==S_FALSE ) { return 2; } SplashForm->ShowProgress( "加载风格模块..." ); u_hMFDll = LoadLibrary(L"StyleUser.dll"); if( u_hMFDll==NULL ){ int err = GetLastError(); return 3; } else if( GetMFFunctions(u_hMFDll)==S_FALSE ) { return 4; } SplashForm->ShowProgress( "加载网络模块..." ); u_hCSDll = LoadLibrary(L"ClientService.dll"); if( u_hCSDll==NULL ){ return 5; } else if( GetCSFunctions(u_hCSDll)==S_FALSE ) { return 6; } u_hQRDll = LoadLibrary(L"QRcode.dll"); if( u_hQRDll ){ GetQRFunctions(u_hQRDll); } return 0; } void FreeDlls() { if( u_hMFDll ){ FreeLibrary( u_hMFDll ); u_hMFDll = NULL; } if( u_hMMDll ){ FreeLibrary( u_hMMDll ); u_hMMDll = NULL; } if( u_hCSDll ){ FreeLibrary( u_hCSDll ); u_hCSDll = NULL; } if( u_hQRDll ){ FreeLibrary( u_hQRDll ); u_hQRDll = NULL; } } WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { hWnd = FindWindow( (LPCTSTR)APPNAME, NULL ); if( hWnd ){ SendMessage( hWnd, UM_RESTORE, 0, 0 ); if( !ParamStr(1).IsEmpty() ){ int BUF_SIZE = 256; TCHAR szName[]=TEXT("MyFileMappingObject"); LPTSTR pBuf; HANDLE hMapFile = CreateFileMapping( INVALID_HANDLE_VALUE, // use paging file NULL, // default security PAGE_READWRITE, // read/write access 0, // max. object size BUF_SIZE, // buffer size szName); // name of mapping object if( hMapFile ){ pBuf = (LPTSTR) MapViewOfFile(hMapFile, // handle to map object FILE_MAP_ALL_ACCESS, // read/write permission 0, 0, BUF_SIZE); if( pBuf ){ wcscpy( pBuf, ParamStr(1).c_str() ); SendMessage( hWnd, UM_LOADPROJECT, 0, wcslen(pBuf) ); UnmapViewOfFile(pBuf); } CloseHandle(hMapFile); } } return 0; } SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)WindowsHook, hInstance, GetCurrentThreadId()); try { Application->Initialize(); Application->MainFormOnTaskBar = true; Application->Title = APPNAME; SplashForm = new TSplashForm(Application); SplashForm->Show(); InitUserPath(); String strErr; int err; switch(LoadDlls()){ case 1: strErr = "加载媒体控制模块失败!"; break; case 2: strErr = "获取媒体控制函数失败!"; break; case 3: strErr = "加载媒体处理模块失败!"; break; case 4: strErr = "获取媒体处理函数失败!"; break; case 5: strErr = "加载网络服务模块失败!"; break; case 6: strErr = "获取网络服务函数失败!"; break; default: break; } MessageForm = new TMessageForm(Application); MessageForm->Position = poDesktopCenter; if( !strErr.IsEmpty() ){ delete SplashForm; FreeDlls(); MessageForm->ShowMessage( strErr, MB_ICONERROR|MB_OK ); delete MessageForm; return 0; } // 初始化GDI+ GdiplusStartup(&theGdiplusToken, &theGdiplusStartupInput, NULL); Application->Title = APPNAME; Application->CreateForm(__classid(TMainForm), &MainForm); Application->MainForm->Visible = false; delete SplashForm; if( !g_lstFonts.empty() ){ Application->MainForm->Visible = true; MessageForm->Position = poMainFormCenter; Application->Run(); } // 关闭GDI+ GdiplusShutdown(theGdiplusToken); delete MessageForm; FreeDlls(); } catch (Exception &exception) { Application->ShowException(&exception); } catch (...) { try { throw Exception(""); } catch (Exception &exception) { Application->ShowException(&exception); } } return 0; } //---------------------------------------------------------------------------