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

📄 setup_c.cpp

📁 This software performs code conversion of Chinese characters, including GB2312/GBK and BIG5. It a
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// setup_c.cpp : chnconv梡僀儞僗僩乕儔

#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "msc.h"

#include "access.h"
#include "brsfolder.h"
#include "codepage.h"
#include "execute.h"
#include "filename.h"
#include "mkdir.h"
#include "mvwnd.h"
#include "oemio.h"
#include "reg.h"
#include "res.h"
#include "resource.h"
#include "sendmsg.h"
#include "shfolder.h"
#include "shortcut.h"
#include "stringex.h"
#include "tmpfile.h"
#include "winmain.h"


#include "chnconv.h"
#include "chnconv_opt.h"
#include "setup_c.h"
#include "conv_reg.h"
#include "conv_opt.h"
#include "conv_opt_old_c.h"


static int nOsCodePage ;         // OS偺僐乕僪儁乕僕

static char szCommandNameA [ MAX_PATH ] ;
static wchar_t szCommandNameW [ MAX_PATH ] ;

#define MAX_PATH_FOLDER          ( MAX_PATH - 0x20 )
#define MAX_PATH_FOLDER_PARENT   ( MAX_PATH - 0x40 )


// ANSI偲UNICODE偺嫟梡僶僢僼傽
typedef union {
   char A [ MAX_PATH ] ;
   wchar_t W [ MAX_PATH ] ;
} FILENAME_BUFFER ;


typedef union {
   char A [ 0x2000 ] ;
   wchar_t W [ 0x2000 ] ;
} MESSAGE_BUFFER ;



int Install ( void ) ;
int PrepareUninstall ( void ) ;
int UninstallA ( const char *szInstallDir ) ;
int UninstallW ( const wchar_t *szInstallDir ) ;



int main ( int argc, char *argv [] ) {


   // for XP Style
   if ( IsWinXPorLater () ) InitCommonControls () ;

   // 僔僗僥儉忣曬傪庢摼
   nOsCodePage = GetACP () ;


   // 堷偒悢偺張棟
   for ( int nCountArgv = 1 ; nCountArgv < argc ; nCountArgv ++ ) {
      char *szArgv = argv [ nCountArgv ] ;
      if ( *szArgv == '/' || *szArgv == '-' ) {
         switch ( szArgv [ 1 ] ) {
            case 'E' :
            case 'e' :
               SetResourceLanguage ( LANGID_ENGLISH ) ;
               break ;
            case 'L' :
            case 'l' :
               if ( *( szArgv + 2 ) ) {
                  char *szString ;
                  errno = 0 ;
                  int nLangId = strtoul ( szArgv + 2, & szString, 0x10 ) ;
                  if ( errno || *szString ) break ;
                  SetResourceLanguage ( nLangId ) ;
                  continue ;
               }
               break ;
            case 'R' :
            case 'r' :
               if ( argv [ nCountArgv + 1 ] && ! stricmp ( argv [ nCountArgv + 1 ], "/yes" ) ) {
                  if ( IsNT () ) UninstallW ( GetArgumentW ( nCountArgv + 2 ) ) ;
                  else           UninstallA ( GetArgumentA ( nCountArgv + 2 ) ) ;
               }
               else {
                  PrepareUninstall () ;
               }
               return 0 ;
            default :
               break ;
         }
      }
   }


   Install () ;
   return 0 ;
}



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



INT_PTR CALLBACK DialogProc ( HWND hWnd, unsigned int dwMessage, WPARAM wParam, LPARAM lParam ) ;
INT_PTR CALLBACK EditDialogProc ( HWND hWnd, unsigned int dwMessage, WPARAM wParam, LPARAM lParam ) ;
int InstallFileA ( HWND hWnd, const char *szFileName, const char *szFolderName ) ;
int InstallFileW ( HWND hWnd, const wchar_t *szFileName, const wchar_t *szFolderName ) ;
int DeleteOldFileA ( HWND hWnd, const char *szFileName, const char *szFolderName ) ;
int DeleteOldFileW ( HWND hWnd, const wchar_t *szFileName, const wchar_t *szFolderName ) ;
int UpdateConfigFile ( HWND hWnd, int nOldVersion ) ;
int MoveOldConfigFile ( HWND hWnd, int nOldVersion ) ;
int MakeBatchFileA ( const char *szFolderName, int IsForEnglish ) ;
int MakeBatchFileW ( const wchar_t *szFolderName, int IsForEnglish ) ;
int MakeShortcutA ( const char *szShortcutFolder, const char *szFolderName, int IsDesktop ) ;
int MakeShortcutW ( const wchar_t *szShortcutFolder, const wchar_t *szFolderName, int IsDesktop ) ;
int DeleteShortcutA ( void ) ;
int DeleteShortcutW ( void ) ;
int DeleteIconCacheA ( void ) ;
int DeleteIconCacheW ( void ) ;
int GetDllVersionA ( const char *szDllFileName ) ;
int GetDllVersionW ( const wchar_t *szDllFileName ) ;
int IsAdministrator ( void ) ;



// 僀儞僗僩乕儖傪幚峴
int Install ( void ) {


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


   // 娗棟幰尃尷偑偁傞偐丠
   if ( IsNT () && ! IsAdministrator () ) {
      if ( IsNT () ) MessageBoxW ( NULL, GetStringW ( IDS_CANNOT_INSTALL ), szCommandNameW, MB_OK ) ;
      else           MessageBoxA ( NULL, GetStringA ( IDS_CANNOT_INSTALL ), szCommandNameA, MB_OK ) ;
      return 0 ;
   }


   // 弶婜僼僅儖僟傪庢摼
   if ( IsNT () ) {

      wchar_t *szString ;

      // 傾儞僀儞僗僩乕儖忣曬偐傜庢摼
      if ( ! GetRegStringW ( HKEY_LOCAL_MACHINE, REG_SUBKEY_UNINSTALL_W, L"UninstallString", szInstallFolderW, MAX_PATH_FOLDER ) && ( szString = wcstokex ( szInstallFolderW, NULL ) ) && *szString ) {
         wcsmove ( szInstallFolderW, szString ) ;
         ChangeFileNameW ( szInstallFolderW, NULL ) ;
         SetPathSeparatorW ( szInstallFolderW, REMOVE_SEPARATOR_ALWAYS ) ;
      }
      // 僷僗忣曬偐傜庢摼
      else if ( ! GetRegStringW ( HKEY_LOCAL_MACHINE, REG_SUBKEY_W, L"Path", szInstallFolderW, MAX_PATH_FOLDER ) && *szInstallFolderW ) {
         // thru
      }
      // 怴婯偵庢摼
      else {
         if ( ! IsWin2000orLater () || GetSpecialFolderPathW ( NULL, szInstallFolderW, CSIDL_PROGRAM_FILES, 0 ) || ! *szInstallFolderW || wcslen ( szInstallFolderW ) >= MAX_PATH_FOLDER_PARENT ) {
            if ( GetRegStringW ( HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion", L"ProgramFilesDir", szInstallFolderW, MAX_PATH ) || ! *szInstallFolderW || wcslen ( szInstallFolderW ) >= MAX_PATH_FOLDER_PARENT ) {
               if ( ! GetEnvironmentVariableW ( L"WINDIR", szInstallFolderW, MAX_PATH ) ) wcscpy ( szInstallFolderW, L"C:\\" ) ;
               wcscpy ( szInstallFolderW + 2, L"\\Program Files" ) ;
            }
         }
         SetPathSeparatorW ( szInstallFolderW, REMOVE_SEPARATOR_ALWAYS ) ;
         wcscat ( szInstallFolderW, L"\\Harigaya\\" ) ;
         wcscat ( szInstallFolderW, FOLDER_NAME_W ) ;
      }

   }
   else {

      char *szString ;

      // 傾儞僀儞僗僩乕儖忣曬偐傜庢摼
      if ( ! GetRegStringA ( HKEY_LOCAL_MACHINE, REG_SUBKEY_UNINSTALL_A, "UninstallString", szInstallFolderA, MAX_PATH_FOLDER ) && ( szString = strtokex ( szInstallFolderA, NULL ) ) && *szString ) {
         strmove ( szInstallFolderA, szString ) ;
         ChangeFileNameA ( szInstallFolderA, NULL ) ;
         SetPathSeparatorA ( szInstallFolderA, REMOVE_SEPARATOR_ALWAYS ) ;
      }
      // 僷僗忣曬偐傜庢摼
      else if ( ! GetRegStringA ( HKEY_LOCAL_MACHINE, REG_SUBKEY_A, "Path", szInstallFolderA, MAX_PATH_FOLDER ) && *szInstallFolderA ) {
         // thru
      }
      // 怴婯偵庢摼
      else {
         if ( ! IsWin2000orLater () || GetSpecialFolderPathA ( NULL, szInstallFolderA, CSIDL_PROGRAM_FILES, 0 ) || ! *szInstallFolderA || strlen ( szInstallFolderA ) >= MAX_PATH_FOLDER_PARENT ) {
            if ( GetRegStringA ( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion", "ProgramFilesDir", szInstallFolderA, MAX_PATH ) || ! *szInstallFolderA || strlen ( szInstallFolderA ) >= MAX_PATH_FOLDER_PARENT ) {
               if ( ! GetEnvironmentVariableA ( "WINDIR", szInstallFolderA, MAX_PATH ) ) strcpy ( szInstallFolderA, "C:\\" ) ;
               strcpy ( szInstallFolderA + 2, "\\Program Files" ) ;
            }
         }
         SetPathSeparatorA ( szInstallFolderA, REMOVE_SEPARATOR_ALWAYS ) ;
         strcat ( szInstallFolderA, "\\Harigaya\\" ) ;
         strcat ( szInstallFolderA, FOLDER_NAME_A ) ;
      }

   }


   // 僟僀傾儘乕僌傪昞帵偟丄僀儞僗僩乕儖傪幚峴
   if ( IsNT () ) DialogBoxExW ( IDD_DIALOG_PROG, NULL, DialogProc ) ;
   else           DialogBoxExA ( IDD_DIALOG_PROG, NULL, DialogProc ) ;


   return 0 ;
}



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

   static int nStep ;
   static int nOldVersion ;

   FILENAME_BUFFER FileName ;


   switch ( dwMessage ) {

      case WM_INITDIALOG :

         MoveWindowToCenter ( hWnd ) ;
         if ( IsNT () ) Dlg_Wm_SetTextW ( hWnd, IDC_STATIC_MESSAGE, GetStringW ( IDS_STEP_ASK_START ) ) ;
         else           Dlg_Wm_SetTextA ( hWnd, IDC_STATIC_MESSAGE, GetStringA ( IDS_STEP_ASK_START ) ) ;
         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, IDOK, GetStringW ( IDS_OK ) ) ;
               else           Dlg_Wm_SetTextA ( hWnd, IDOK, GetStringA ( IDS_OK ) ) ;
               if ( IsNT () ) Dlg_Wm_SetTextW ( hWnd, IDCANCEL, GetStringW ( IDS_CANCEL ) ) ;
               else           Dlg_Wm_SetTextA ( hWnd, IDCANCEL, GetStringA ( IDS_CANCEL ) ) ;

               ASK_FOLDER_PROC :

               if ( IsNT () ) SetPathSeparatorW ( szInstallFolderW, ADD_SEPARATOR_ONLY_ROOT ) ;
               else           SetPathSeparatorA ( szInstallFolderA, ADD_SEPARATOR_ONLY_ROOT ) ;

               if ( IsNT () ) Dlg_Wm_SetTextW ( hWnd, IDC_STATIC_MESSAGE, GetStringW ( IDS_STEP_ASK_FOLDER ) ) ;
               else           Dlg_Wm_SetTextA ( hWnd, IDC_STATIC_MESSAGE, GetStringA ( IDS_STEP_ASK_FOLDER ) ) ;
               if ( IsNT () ) Dlg_Wm_SetTextW ( hWnd, IDC_STATIC_PROG, szInstallFolderW ) ;
               else           Dlg_Wm_SetTextA ( hWnd, IDC_STATIC_PROG, szInstallFolderA ) ;
               if ( IsNT () ) Dlg_Wm_SetTextW ( hWnd, IDCANCEL, GetStringW ( IDS_CHANGE ) ) ;
               else           Dlg_Wm_SetTextA ( hWnd, IDCANCEL, GetStringA ( IDS_CHANGE ) ) ;

               if ( IsNT () ) SetPathSeparatorW ( szInstallFolderW, REMOVE_SEPARATOR_ALWAYS ) ;
               else           SetPathSeparatorA ( szInstallFolderA, REMOVE_SEPARATOR_ALWAYS ) ;

               Dlg_Button_SetStyle ( hWnd, IDOK, BS_DEFPUSHBUTTON, TRUE ) ;
               Dlg_SetFocus ( hWnd, IDOK ) ;
               MessageBeep ( MB_OK ) ;
               nStep = 1 ;
               return TRUE ;
            }

            break ;
         }


         // 僗僥僢僾侾
         if ( nStep == 1 ) {

            // 僼僅儖僟傪曄峏
            if ( LOWORD ( wParam ) == IDCANCEL ) {

               if ( IsNT () ) SetPathSeparatorW ( szInstallFolderW, ADD_SEPARATOR_ONLY_ROOT ) ;
               else           SetPathSeparatorA ( szInstallFolderA, ADD_SEPARATOR_ONLY_ROOT ) ;

               intptr_t nResult ;
               if ( IsNT () ) nResult = DialogBoxExW ( IDD_DIALOG_EDIT, hWnd, EditDialogProc ) ;
               else           nResult = DialogBoxExA ( IDD_DIALOG_EDIT, hWnd, EditDialogProc ) ;

               if ( IsNT () ) SetPathSeparatorW ( szInstallFolderW, REMOVE_SEPARATOR_ALWAYS ) ;
               else           SetPathSeparatorA ( szInstallFolderA, REMOVE_SEPARATOR_ALWAYS ) ;

               if ( nResult ) {
                  if ( IsNT () ) Dlg_Wm_SetTextW ( hWnd, IDC_STATIC_MESSAGE, GetStringW ( IDS_STEP_CANCEL ) ) ;
                  else           Dlg_Wm_SetTextA ( hWnd, IDC_STATIC_MESSAGE, GetStringA ( IDS_STEP_CANCEL ) ) ;
                  if ( IsNT () ) Dlg_Wm_SetTextW ( hWnd, IDOK, GetStringW ( IDS_CONTINUE ) ) ;
                  else           Dlg_Wm_SetTextA ( hWnd, IDOK, GetStringA ( IDS_CONTINUE ) ) ;
                  if ( IsNT () ) Dlg_Wm_SetTextW ( hWnd, IDCANCEL, GetStringW ( IDS_STOP ) ) ;
                  else           Dlg_Wm_SetTextA ( hWnd, IDCANCEL, GetStringA ( IDS_STOP ) ) ;
                  Dlg_Button_SetStyle ( hWnd, IDOK, BS_DEFPUSHBUTTON, TRUE ) ;
                  Dlg_SetFocus ( hWnd, IDOK ) ;
                  MessageBeep ( MB_OK ) ;
                  nStep = 0 ;
                  return TRUE ;
               }

               goto ASK_FOLDER_PROC ;
            }

            // 僼傽僀儖傪僐僺乕
            if ( LOWORD ( wParam ) == IDOK ) {

⌨️ 快捷键说明

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