⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setup_c.cpp

📁 This software performs code conversion of Chinese characters, including GB2312/GBK and BIG5. It a
💻 CPP
📖 第 1 页 / 共 5 页
字号:

   int nVersion = GetDllVersion () ;
   FreeLibrary ( hDll ) ;

   return nVersion ;
}



// DLL 偺僶乕僕儑儞傪庢摼乮UNICODE斉乯
int GetDllVersionW ( const wchar_t *szDllFileName ) {

   HINSTANCE hDll = LoadLibraryW ( szDllFileName ) ;

   GETDLLVERSION GetDllVersion = NULL ;
   if ( GETPROCADDRESS ( hDll, GETDLLVERSION, GetDllVersion ) ) return 0 ;

   int nVersion = GetDllVersion () ;
   FreeLibrary ( hDll ) ;

   return nVersion ;
}



// 娗棟幰尃尷偑偁傞偐傪曉偡
int IsAdministrator ( void ) {

   if ( IsNT () ) {

      wchar_t szRegKey [ MAX_PATH ] ;
      wcscpy ( szRegKey, REG_SUBKEY_UNINSTALL_W ) ;

      ChangeFileNameW ( szRegKey, NULL ) ;
      SetPathSeparatorW ( szRegKey, REMOVE_SEPARATOR_ALWAYS ) ;
      ChangeFileNameW ( szRegKey, NULL ) ;
      SetPathSeparatorW ( szRegKey, REMOVE_SEPARATOR_ALWAYS ) ;

      return IsRegKeyAccessibleW ( HKEY_LOCAL_MACHINE, szRegKey, KEY_WRITE ) ;

   }
   else {

      char szRegKey [ MAX_PATH ] ;
      strcpy ( szRegKey, REG_SUBKEY_UNINSTALL_A ) ;

      ChangeFileNameA ( szRegKey, NULL ) ;
      SetPathSeparatorA ( szRegKey, REMOVE_SEPARATOR_ALWAYS ) ;
      ChangeFileNameA ( szRegKey, NULL ) ;
      SetPathSeparatorA ( szRegKey, REMOVE_SEPARATOR_ALWAYS ) ;

      return IsRegKeyAccessibleA ( HKEY_LOCAL_MACHINE, szRegKey, KEY_WRITE ) ;

   }
}



////////////////////////////////////////////////////////
//                 傾儞僀儞僗僩乕儖                   //
////////////////////////////////////////////////////////



INT_PTR CALLBACK UninstallDialogProc ( HWND hWnd, unsigned int dwMessage, WPARAM wParam, LPARAM lParam ) ;
int UninstallFileA ( HWND hWnd, const char *szFileName ) ;
int UninstallFileW ( HWND hWnd, const wchar_t *szFileName ) ;
int UninstallShortcutA ( HWND hWnd, const char *szShortcutFolder, int IsDesktop ) ;
int UninstallShortcutW ( HWND hWnd, const wchar_t *szShortcutFolder, int IsDesktop ) ;
int UninstallConfigFile ( HWND hWnd ) ;
int IsSpecialFolderA ( const char *szFolderName ) ;
int IsSpecialFolderW ( const wchar_t *szFolderName ) ;



static const char szTempFileHeaderA [] =     "sur" ;
static const wchar_t szTempFileHeaderW [] = L"sur" ;



// 傾儞僀儞僗僩乕儖傪弨旛
int PrepareUninstall ( void ) {

   // 暥帤楍傪弶婜壔
   LoadStringExA ( IDS_COMMANDNAME, szCommandNameA, MAX_PATH ) ;
   LoadStringExW ( IDS_COMMANDNAME, szCommandNameW, MAX_PATH ) ;

   if ( IsNT () ) {

      wchar_t szSrcFileName [ MAX_PATH ] ;
      wchar_t szDstFileName [ MAX_PATH ] ;
      wchar_t szCmdLine [ MAX_PATH * 2 ] ;

      GetModuleFileNameW ( NULL, szSrcFileName, MAX_PATH ) ;

      GetTempFileNameExW ( szTempFileHeaderW, szDstFileName ) ;
//    ChangeExtensionW ( szDstFileName, L"exe" ) ;

      CopyFileW ( szSrcFileName, szDstFileName, FALSE ) ;

      ChangeFileNameW ( szSrcFileName, NULL ) ;
      SetPathSeparatorW ( szSrcFileName, REMOVE_SEPARATOR_ALWAYS ) ;
      swprintf ( szCmdLine, L"\"%s\" /r /yes \"%s\"", szDstFileName, szSrcFileName ) ;

      // 僇儗儞僩僨傿儗僋僩儕傪曄偊偰偍偐側偄偲丄巕僾儘僙僗偱僼僅儖僟偑嶍彍偱偒側偄
      ChangeFileNameW ( szDstFileName, NULL ) ;
      SetPathSeparatorW ( szDstFileName, REMOVE_SEPARATOR_ALWAYS ) ;
      SetCurrentDirectoryW ( szDstFileName ) ;

      ExecuteW ( szCmdLine, SW_SHOWDEFAULT, 0, NULL ) ;
   }
   else {

      char szSrcFileName [ MAX_PATH ] ;
      char szDstFileName [ MAX_PATH ] ;
      char szCmdLine [ MAX_PATH * 2 ] ;

      GetModuleFileNameA ( NULL, szSrcFileName, MAX_PATH ) ;

      GetTempFileNameExA ( szTempFileHeaderA, szDstFileName ) ;
//    ChangeExtensionA ( szDstFileName, "exe" ) ;

      CopyFileA ( szSrcFileName, szDstFileName, FALSE ) ;

      ChangeFileNameA ( szSrcFileName, NULL ) ;
      SetPathSeparatorA ( szSrcFileName, REMOVE_SEPARATOR_ALWAYS ) ;
      sprintf ( szCmdLine, "\"%s\" /r /yes \"%s\"", szDstFileName, szSrcFileName ) ;

      // 僇儗儞僩僨傿儗僋僩儕傪曄偊偰偍偐側偄偲丄巕僾儘僙僗偱僼僅儖僟偑嶍彍偱偒側偄
      ChangeFileNameA ( szDstFileName, NULL ) ;
      SetPathSeparatorA ( szDstFileName, REMOVE_SEPARATOR_ALWAYS ) ;
      SetCurrentDirectoryA ( szDstFileName ) ;

      ExecuteA ( szCmdLine, SW_SHOWDEFAULT, 0, NULL ) ;
   }

   return 0 ;
}



// 傾儞僀儞僗僩乕儖傪幚峴乮ANSI斉乯
int UninstallA ( const char *szInstallDir ) {

   // 暥帤楍傪弶婜壔
   LoadStringExA ( IDS_COMMANDNAME, szCommandNameA, MAX_PATH ) ;
   LoadStringExW ( IDS_COMMANDNAME, szCommandNameW, MAX_PATH ) ;

   // 娗棟幰尃尷偑偁傞偐丠
   if ( IsNT () && ! IsAdministrator () ) {
      MessageBoxA ( NULL, GetStringA ( IDS_CANNOT_INSTALL ), szCommandNameA, MB_OK ) ;
   }
   else {
      // 僟僀傾儘乕僌傪昞帵偟丄傾儞僀儞僗僩乕儖傪幚峴
      DialogBoxParamExA ( IDD_DIALOG_PROG, NULL, UninstallDialogProc, (LPARAM) szInstallDir ) ;
   }

   // 帺恎傪嶍彍
   char szSelfFileName [ MAX_PATH ] ;
   char szBatchFileName [ MAX_PATH ] ;
   char szCmdLine [ MAX_PATH * 2 ] ;

   GetModuleFileNameA ( NULL, szSelfFileName, MAX_PATH ) ;
   GetModuleFileNameA ( NULL, szBatchFileName, MAX_PATH ) ;
   ChangeExtensionA ( szBatchFileName, "bat" ) ;

   FILE *Fout = fsopen ( szBatchFileName, "w", _SH_DENYWR ) ;
   if ( ! Fout ) return 1 ;
   fprintf ( Fout, "del \"%s\"\n", szSelfFileName ) ;
   fprintf ( Fout, "del \"%s\"\n", szBatchFileName ) ;
   fclose ( Fout ) ;

   sprintf ( szCmdLine, "\"%s\" /c \"%s\"", IsNT () ? "cmd.exe" : "command.com", szBatchFileName ) ;

   ExecuteA ( szCmdLine, SW_HIDE, 0, NULL ) ;
   return 0 ;
}



// 傾儞僀儞僗僩乕儖傪幚峴乮UNICODE斉乯
int UninstallW ( const wchar_t *szInstallDir ) {

   // 暥帤楍傪弶婜壔
   LoadStringExA ( IDS_COMMANDNAME, szCommandNameA, MAX_PATH ) ;
   LoadStringExW ( IDS_COMMANDNAME, szCommandNameW, MAX_PATH ) ;

   // 娗棟幰尃尷偑偁傞偐丠
   if ( IsNT () && ! IsAdministrator () ) {
      MessageBoxW ( NULL, GetStringW ( IDS_CANNOT_INSTALL ), szCommandNameW, MB_OK ) ;
   }
   else {
      // 僟僀傾儘乕僌傪昞帵偟丄傾儞僀儞僗僩乕儖傪幚峴
      DialogBoxParamExW ( IDD_DIALOG_PROG, NULL, UninstallDialogProc, (LPARAM) szInstallDir ) ;
   }

   // 帺恎傪嶍彍
   wchar_t szSelfFileName [ MAX_PATH ] ;
   wchar_t szBatchFileName [ MAX_PATH ] ;
   wchar_t szCmdLine [ MAX_PATH * 2 ] ;

   GetModuleFileNameW ( NULL, szSelfFileName, MAX_PATH ) ;
   GetModuleFileNameW ( NULL, szBatchFileName, MAX_PATH ) ;
   ChangeExtensionW ( szBatchFileName, L"bat" ) ;

   FILE *Fout = wfsopen ( szBatchFileName, L"w", _SH_DENYWR ) ;
   if ( Fout == NULL ) return 1 ;
   fwprintf ( Fout, L"del \"%s\"\n", szSelfFileName ) ;
   fwprintf ( Fout, L"del \"%s\"\n", szBatchFileName ) ;
   fclose ( Fout ) ;

   swprintf ( szCmdLine, L"\"%s\" /c \"%s\"", IsNT () ? L"cmd.exe" : L"command.com", szBatchFileName ) ;

   ExecuteW ( szCmdLine, SW_HIDE, 0, NULL ) ;
   return 0 ;
}



// 昞帵僐儞僩儘乕儖
INT_PTR CALLBACK UninstallDialogProc ( HWND hWnd, unsigned int dwMessage, WPARAM wParam, LPARAM lParam ) {

   static char *szInstallDirA ;
   static wchar_t *szInstallDirW ;
   static MESSAGE_BUFFER Message ;
   static int IsFailed ;
   static int nStep ;

   FILENAME_BUFFER FileName ;


   switch ( dwMessage ) {

      case WM_INITDIALOG :

         if ( IsNT () ) szInstallDirW = (wchar_t*) lParam ;
         else           szInstallDirA = (char*) lParam ;

         MoveWindowToCenter ( hWnd ) ;
         if ( IsNT () ) Dlg_Wm_SetTextW ( hWnd, IDC_STATIC_MESSAGE, GetStringW ( IDS_UNINSTALL_ASK ) ) ;
         else           Dlg_Wm_SetTextA ( hWnd, IDC_STATIC_MESSAGE, GetStringA ( IDS_UNINSTALL_ASK ) ) ;
         MessageBeep ( MB_OK ) ;
         nStep = 0 ;
         return TRUE ;


      case WM_COMMAND :

         // 僗僥僢僾侽
         if ( nStep == 0 ) {

            // 壗傕偣偢偵廔椆
            if ( LOWORD ( wParam ) == IDCANCEL ) {
               EndDialog ( hWnd, 0 ) ;
               return TRUE ;
            }

            // 幚峴
            if ( LOWORD ( wParam ) == IDOK ) {

               if ( IsNT () ) Dlg_Wm_SetTextW ( hWnd, IDC_STATIC_MESSAGE, GetStringW ( IDS_DELETING_FILE ) ) ;
               else           Dlg_Wm_SetTextA ( hWnd, IDC_STATIC_MESSAGE, GetStringA ( IDS_DELETING_FILE ) ) ;

               if ( IsNT () ) wcscpy ( Message.W, GetStringW ( IDS_UNINSTALL_FAILED ) ) ;
               else           strcpy ( Message.A, GetStringA ( IDS_UNINSTALL_FAILED ) ) ;

               // 僼傽僀儖傪嶍彍
               if ( IsNT () ) {

                  for ( int nCount = 0 ; ( InstallFileName [ nCount ] ).W ; nCount ++ ) {
                     swprintf ( FileName.W, L"%s\\%s", szInstallDirW, ( InstallFileName [ nCount ] ).W ) ;
                     if ( UninstallFileW ( hWnd, FileName.W ) ) {
                        swprintf ( wcsend ( Message.W ), L"%s\n", FileName.W ) ;
                        IsFailed = 1 ;
                     }
                  }
                  for ( int nCount = 0 ; ( OldFileName [ nCount ] ).W ; nCount ++ ) {
                     swprintf ( FileName.W, L"%s\\%s", szInstallDirW, ( OldFileName [ nCount ] ).W ) ;
                     UninstallFileW ( hWnd, FileName.W ) ;
                  }
                  for ( int nCount = 0 ; ( OldBatFileName [ nCount ] ).W ; nCount ++ ) {
                     swprintf ( FileName.W, L"%s\\%s", szInstallDirW, ( OldBatFileName [ nCount ] ).W ) ;
                     UninstallFileW ( hWnd, FileName.W ) ;
                  }

               }
               else {

                  for ( int nCount = 0 ; ( InstallFileName [ nCount ] ).A ; nCount ++ ) {
                     sprintf ( FileName.A, "%s\\%s", szInstallDirA, ( InstallFileName [ nCount ] ).A ) ;
                     if ( UninstallFileA ( hWnd, FileName.A ) ) {
                        sprintf ( strend ( Message.A ), "%s\n", FileName.A ) ;
                        IsFailed = 1 ;
                     }
                  }
                  for ( int nCount = 0 ; ( OldFileName [ nCount ] ).A ; nCount ++ ) {
                     sprintf ( FileName.A, "%s\\%s", szInstallDirA, ( OldFileName [ nCount ] ).A ) ;
                     UninstallFileA ( hWnd, FileName.A ) ;
                  }
                  for ( int nCount = 0 ; ( OldBatFileName [ nCount ] ).A ; nCount ++ ) {
                     sprintf ( FileName.A, "%s\\%s", szInstallDirA, ( OldBatFileName [ nCount ] ).A ) ;
                     UninstallFileA ( hWnd, FileName.A ) ;
                  }

               }


               // 娐嫬僼傽僀儖傪嶍彍
               if ( IsNT () ) {
                  swprintf ( FileName.W, L"%s\\%s", szInstallDirW, CFG_FILENAME_W ) ;
                  UninstallFileW ( hWnd, FileName.W ) ;
               }
               else {
                  sprintf ( FileName.A, "%s\\%s", szInstallDirA, CFG_FILENAME_A ) ;
                  UninstallFileA ( hWnd, FileName.A ) ;
               }

               // 僶僢僠僼傽僀儖傪嶍彍
               if ( IsNT () ) {
                  swprintf ( FileName.W, L"%s\\%s", szInstallDirW, BATCH_FILE_NAME_J_W ) ;
                  UninstallFileW ( hWnd, FileName.W ) ;
                  swprintf ( FileName.W, L"%s\\%s", szInstallDirW, BATCH_FILE_NAME_E_W ) ;
                  UninstallFileW ( hWnd, FileName.W ) ;
               }
               else {
                  sprintf ( FileName.A, "%s\\%s", szInstallDirA, BATCH_FILE_NAME_J_A ) ;
                  UninstallFileA ( hWnd, FileName.A ) ;
                  sprintf ( FileName.A, "%s\\%s", szInstallDirA, BATCH_FILE_NAME_E_A ) ;
                  UninstallFileA ( hWnd, FileName.A ) ;
               }

     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -