void NormalizeDirPathPrefix(CSysString &dirPath) { if (dirPath.IsEmpty()) return; if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1) dirPath += kDirDelimiter; }
bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings) { driveStrings.Clear(); UINT32 size = GetLogicalDriveStrings(0, NULL); if (size == 0) return false; CSysString buffer; UINT32 newSize = GetLogicalDriveStrings(size, buffer.GetBuffer(size)); if (newSize == 0) return false; if (newSize > size) return false; CSysString string; for (UINT32 i = 0; i < newSize; i++) { TCHAR c = buffer[i]; if (c == TEXT('\0')) { driveStrings.Add(string); string.Empty(); } else string += c; } if (!string.IsEmpty()) return false; return true; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */,int /* nCmdShow */) { g_hInstance = (HINSTANCE)hInstance; #ifndef _UNICODE g_IsNT = IsItWindowsNT(); #endif InitCommonControls(); UString archiveName, switches; #ifdef _SHELL_EXECUTE UString executeFile, executeParameters; #endif NCommandLineParser::SplitCommandLine(GetCommandLineW(), archiveName, switches); UString fullPath; NDLL::MyGetModuleFileName(g_hInstance, fullPath); switches.Trim(); bool assumeYes = false; if (switches.Left(2).CompareNoCase(UString(L"-y")) == 0) { assumeYes = true; switches = switches.Mid(2); switches.Trim(); } AString config; if (!ReadDataString(fullPath, kStartID, kEndID, config)) { if (!assumeYes) ShowErrorMessage(L"Can't load config info"); return 1; } UString dirPrefix = L"." WSTRING_PATH_SEPARATOR; UString appLaunched; bool showProgress = true; if (!config.IsEmpty()) { CObjectVector<CTextConfigPair> pairs; if (!GetTextConfig(config, pairs)) { if (!assumeYes) ShowErrorMessage(L"Config failed"); return 1; } UString friendlyName = GetTextConfigValue(pairs, L"Title"); UString installPrompt = GetTextConfigValue(pairs, L"BeginPrompt"); UString progress = GetTextConfigValue(pairs, L"Progress"); if (progress.CompareNoCase(L"no") == 0) showProgress = false; int index = FindTextConfigItem(pairs, L"Directory"); if (index >= 0) dirPrefix = pairs[index].String; if (!installPrompt.IsEmpty() && !assumeYes) { if (MessageBoxW(0, installPrompt, friendlyName, MB_YESNO | MB_ICONQUESTION) != IDYES) return 0; } appLaunched = GetTextConfigValue(pairs, L"RunProgram"); #ifdef _SHELL_EXECUTE executeFile = GetTextConfigValue(pairs, L"ExecuteFile"); executeParameters = GetTextConfigValue(pairs, L"ExecuteParameters") + switches; #endif } NFile::NDirectory::CTempDirectory tempDir; if (!tempDir.Create(kTempDirPrefix)) { if (!assumeYes) ShowErrorMessage(L"Can not create temp folder archive"); return 1; } CCodecs *codecs = new CCodecs; CMyComPtr<IUnknown> compressCodecsInfo = codecs; HRESULT result = codecs->Load(); if (result != S_OK) { ShowErrorMessage(L"Can not load codecs"); return 1; } UString tempDirPath = GetUnicodeString(tempDir.GetPath()); { bool isCorrupt = false; UString errorMessage; HRESULT result = ExtractArchive(codecs, fullPath, tempDirPath, showProgress, isCorrupt, errorMessage); if (result != S_OK) { if (!assumeYes) { if (result == S_FALSE || isCorrupt) { errorMessage = NWindows::MyLoadStringW(IDS_EXTRACTION_ERROR_MESSAGE); result = E_FAIL; } if (result != E_ABORT && !errorMessage.IsEmpty()) ::MessageBoxW(0, errorMessage, NWindows::MyLoadStringW(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR); } return 1; } } CCurrentDirRestorer currentDirRestorer; if (!SetCurrentDirectory(tempDir.GetPath())) return 1; HANDLE hProcess = 0; #ifdef _SHELL_EXECUTE if (!executeFile.IsEmpty()) { CSysString filePath = GetSystemString(executeFile); SHELLEXECUTEINFO execInfo; execInfo.cbSize = sizeof(execInfo); execInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT; execInfo.hwnd = NULL; execInfo.lpVerb = NULL; execInfo.lpFile = filePath; if (!switches.IsEmpty()) executeParameters += switches; CSysString parametersSys = GetSystemString(executeParameters); if (parametersSys.IsEmpty()) execInfo.lpParameters = NULL; else execInfo.lpParameters = parametersSys; execInfo.lpDirectory = NULL; execInfo.nShow = SW_SHOWNORMAL; execInfo.hProcess = 0; /* BOOL success = */ ::ShellExecuteEx(&execInfo); UINT32 result = (UINT32)(UINT_PTR)execInfo.hInstApp; if(result <= 32) { if (!assumeYes) ShowErrorMessage(L"Can not open file"); return 1; } hProcess = execInfo.hProcess; } else #endif { if (appLaunched.IsEmpty()) { appLaunched = L"setup.exe"; if (!NFile::NFind::DoesFileExist(GetSystemString(appLaunched))) { if (!assumeYes) ShowErrorMessage(L"Can not find setup.exe"); return 1; } } { UString s2 = tempDirPath; NFile::NName::NormalizeDirPathPrefix(s2); appLaunched.Replace(L"%%T" WSTRING_PATH_SEPARATOR, s2); } appLaunched.Replace(L"%%T", tempDirPath); if (!switches.IsEmpty()) { appLaunched += L' '; appLaunched += switches; } STARTUPINFO startupInfo; startupInfo.cb = sizeof(startupInfo); startupInfo.lpReserved = 0; startupInfo.lpDesktop = 0; startupInfo.lpTitle = 0; startupInfo.dwFlags = 0; startupInfo.cbReserved2 = 0; startupInfo.lpReserved2 = 0; PROCESS_INFORMATION processInformation; CSysString appLaunchedSys = GetSystemString(dirPrefix + appLaunched); BOOL createResult = CreateProcess(NULL, (LPTSTR)(LPCTSTR)appLaunchedSys, NULL, NULL, FALSE, 0, NULL, NULL /*tempDir.GetPath() */, &startupInfo, &processInformation); if (createResult == 0) { if (!assumeYes) ShowLastErrorMessage(); return 1; } ::CloseHandle(processInformation.hThread); hProcess = processInformation.hProcess; } if (hProcess != 0) { WaitForSingleObject(hProcess, INFINITE); ::CloseHandle(hProcess); } return 0; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, #ifdef UNDER_CE LPWSTR #else LPSTR #endif /* lpCmdLine */,int /* nCmdShow */) { g_hInstance = (HINSTANCE)hInstance; NT_CHECK #ifdef _WIN32 LoadSecurityDlls(); #endif // InitCommonControls(); UString archiveName, switches; #ifdef _SHELL_EXECUTE UString executeFile, executeParameters; #endif NCommandLineParser::SplitCommandLine(GetCommandLineW(), archiveName, switches); FString fullPath; NDLL::MyGetModuleFileName(fullPath); switches.Trim(); bool assumeYes = false; if (switches.IsPrefixedBy_Ascii_NoCase("-y")) { assumeYes = true; switches = switches.Ptr(2); switches.Trim(); } AString config; if (!ReadDataString(fullPath, kStartID, kEndID, config)) { if (!assumeYes) ShowErrorMessage(L"Can't load config info"); return 1; } UString dirPrefix = L"." WSTRING_PATH_SEPARATOR; UString appLaunched; bool showProgress = true; if (!config.IsEmpty()) { CObjectVector<CTextConfigPair> pairs; if (!GetTextConfig(config, pairs)) { if (!assumeYes) ShowErrorMessage(L"Config failed"); return 1; } UString friendlyName = GetTextConfigValue(pairs, L"Title"); UString installPrompt = GetTextConfigValue(pairs, L"BeginPrompt"); UString progress = GetTextConfigValue(pairs, L"Progress"); if (progress.IsEqualTo_Ascii_NoCase("no")) showProgress = false; int index = FindTextConfigItem(pairs, L"Directory"); if (index >= 0) dirPrefix = pairs[index].String; if (!installPrompt.IsEmpty() && !assumeYes) { if (MessageBoxW(0, installPrompt, friendlyName, MB_YESNO | MB_ICONQUESTION) != IDYES) return 0; } appLaunched = GetTextConfigValue(pairs, L"RunProgram"); #ifdef _SHELL_EXECUTE executeFile = GetTextConfigValue(pairs, L"ExecuteFile"); executeParameters = GetTextConfigValue(pairs, L"ExecuteParameters"); #endif } CTempDir tempDir; if (!tempDir.Create(kTempDirPrefix)) { if (!assumeYes) ShowErrorMessage(L"Can not create temp folder archive"); return 1; } CCodecs *codecs = new CCodecs; CMyComPtr<IUnknown> compressCodecsInfo = codecs; { HRESULT result = codecs->Load(); if (result != S_OK) { ShowErrorMessage(L"Can not load codecs"); return 1; } } const FString tempDirPath = tempDir.GetPath(); // tempDirPath = L"M:\\1\\"; // to test low disk space { bool isCorrupt = false; UString errorMessage; HRESULT result = ExtractArchive(codecs, fullPath, tempDirPath, showProgress, isCorrupt, errorMessage); if (result != S_OK) { if (!assumeYes) { if (result == S_FALSE || isCorrupt) { NWindows::MyLoadString(IDS_EXTRACTION_ERROR_MESSAGE, errorMessage); result = E_FAIL; } if (result != E_ABORT) { if (errorMessage.IsEmpty()) errorMessage = NError::MyFormatMessage(result); ::MessageBoxW(0, errorMessage, NWindows::MyLoadString(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR); } } return 1; } } #ifndef UNDER_CE CCurrentDirRestorer currentDirRestorer; if (!SetCurrentDir(tempDirPath)) return 1; #endif HANDLE hProcess = 0; #ifdef _SHELL_EXECUTE if (!executeFile.IsEmpty()) { CSysString filePath = GetSystemString(executeFile); SHELLEXECUTEINFO execInfo; execInfo.cbSize = sizeof(execInfo); execInfo.fMask = SEE_MASK_NOCLOSEPROCESS #ifndef UNDER_CE | SEE_MASK_FLAG_DDEWAIT #endif ; execInfo.hwnd = NULL; execInfo.lpVerb = NULL; execInfo.lpFile = filePath; if (!switches.IsEmpty()) { executeParameters.Add_Space_if_NotEmpty(); executeParameters += switches; } CSysString parametersSys = GetSystemString(executeParameters); if (parametersSys.IsEmpty()) execInfo.lpParameters = NULL; else execInfo.lpParameters = parametersSys; execInfo.lpDirectory = NULL; execInfo.nShow = SW_SHOWNORMAL; execInfo.hProcess = 0; /* BOOL success = */ ::ShellExecuteEx(&execInfo); UINT32 result = (UINT32)(UINT_PTR)execInfo.hInstApp; if (result <= 32) { if (!assumeYes) ShowErrorMessage(L"Can not open file"); return 1; } hProcess = execInfo.hProcess; } else #endif { if (appLaunched.IsEmpty()) { appLaunched = L"setup.exe"; if (!NFind::DoesFileExist(us2fs(appLaunched))) { if (!assumeYes) ShowErrorMessage(L"Can not find setup.exe"); return 1; } } { FString s2 = tempDirPath; NName::NormalizeDirPathPrefix(s2); appLaunched.Replace(L"%%T" WSTRING_PATH_SEPARATOR, fs2us(s2)); } UString appNameForError = appLaunched; // actually we need to rtemove parameters also appLaunched.Replace(L"%%T", fs2us(tempDirPath)); if (!switches.IsEmpty()) { appLaunched.Add_Space(); appLaunched += switches; } STARTUPINFO startupInfo; startupInfo.cb = sizeof(startupInfo); startupInfo.lpReserved = 0; startupInfo.lpDesktop = 0; startupInfo.lpTitle = 0; startupInfo.dwFlags = 0; startupInfo.cbReserved2 = 0; startupInfo.lpReserved2 = 0; PROCESS_INFORMATION processInformation; CSysString appLaunchedSys = GetSystemString(dirPrefix + appLaunched); BOOL createResult = CreateProcess(NULL, (LPTSTR)(LPCTSTR)appLaunchedSys, NULL, NULL, FALSE, 0, NULL, NULL /*tempDir.GetPath() */, &startupInfo, &processInformation); if (createResult == 0) { if (!assumeYes) { // we print name of exe file, if error message is // ERROR_BAD_EXE_FORMAT: "%1 is not a valid Win32 application". ShowErrorMessageSpec(appNameForError); } return 1; } ::CloseHandle(processInformation.hThread); hProcess = processInformation.hProcess; } if (hProcess != 0) { WaitForSingleObject(hProcess, INFINITE); ::CloseHandle(hProcess); } return 0; }
static HRESULT StartApplication(const UString &dir, const UString &path, HWND window, CProcess &process) { UINT32 result; #ifndef _UNICODE if (g_IsNT) { SHELLEXECUTEINFOW execInfo; execInfo.cbSize = sizeof(execInfo); execInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT; execInfo.hwnd = NULL; execInfo.lpVerb = NULL; execInfo.lpFile = path; execInfo.lpParameters = NULL; execInfo.lpDirectory = dir.IsEmpty() ? NULL : (LPCWSTR)dir; execInfo.nShow = SW_SHOWNORMAL; execInfo.hProcess = 0; ShellExecuteExWP shellExecuteExW = (ShellExecuteExWP) ::GetProcAddress(::GetModuleHandleW(L"shell32.dll"), "ShellExecuteExW"); if (shellExecuteExW == 0) return 0; shellExecuteExW(&execInfo); result = (UINT32)(UINT_PTR)execInfo.hInstApp; process.Attach(execInfo.hProcess); } else #endif { SHELLEXECUTEINFO execInfo; execInfo.cbSize = sizeof(execInfo); execInfo.fMask = SEE_MASK_NOCLOSEPROCESS #ifndef UNDER_CE | SEE_MASK_FLAG_DDEWAIT #endif ; execInfo.hwnd = NULL; execInfo.lpVerb = NULL; const CSysString sysPath = GetSystemString(path); const CSysString sysDir = GetSystemString(dir); execInfo.lpFile = sysPath; execInfo.lpParameters = NULL; execInfo.lpDirectory = #ifdef UNDER_CE NULL #else sysDir.IsEmpty() ? NULL : (LPCTSTR)sysDir #endif ; execInfo.nShow = SW_SHOWNORMAL; execInfo.hProcess = 0; ::ShellExecuteEx(&execInfo); result = (UINT32)(UINT_PTR)execInfo.hInstApp; process.Attach(execInfo.hProcess); } if (result <= 32) { switch(result) { case SE_ERR_NOASSOC: ::MessageBoxW(window, NError::MyFormatMessageW(::GetLastError()), // L"There is no application associated with the given file name extension", L"7-Zip", MB_OK | MB_ICONSTOP); } } return S_OK; }
NFileOperationReturnCode::EEnum CPlugin::GetFilesReal(struct PluginPanelItem *panelItems, int itemsNumber, int move, const char *_aDestPath, int opMode, bool showBox) { if(move != 0) { g_StartupInfo.ShowMessage(NMessageID::kMoveIsNotSupported); return NFileOperationReturnCode::kError; } CSysString destPath = _aDestPath; NFile::NName::NormalizeDirPathPrefix(destPath); bool extractSelectedFiles = true; NExtract::CInfo extractionInfo; extractionInfo.PathMode = NExtract::NPathMode::kCurrentPathnames; extractionInfo.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt; bool silent = (opMode & OPM_SILENT) != 0; bool decompressAllItems = false; UString password = Password; bool passwordIsDefined = PasswordIsDefined; if (!silent) { const int kPathIndex = 2; ReadExtractionInfo(extractionInfo); const int kPathModeRadioIndex = 4; const int kOverwriteModeRadioIndex = kPathModeRadioIndex + 4; const int kNumOverwriteOptions = 6; const int kFilesModeIndex = kOverwriteModeRadioIndex + kNumOverwriteOptions; const int kXSize = 76; const int kYSize = 19; const int kPasswordYPos = 12; const int kXMid = kXSize / 2; AString oemPassword = UnicodeStringToMultiByte(password, CP_OEMCP); struct CInitDialogItem initItems[]={ { DI_DOUBLEBOX, 3, 1, kXSize - 4, kYSize - 2, false, false, 0, false, NMessageID::kExtractTitle, NULL, NULL }, { DI_TEXT, 5, 2, 0, 0, false, false, 0, false, NMessageID::kExtractTo, NULL, NULL }, { DI_EDIT, 5, 3, kXSize - 6, 3, true, false, DIF_HISTORY, false, -1, destPath, kExractPathHistoryName}, // { DI_EDIT, 5, 3, kXSize - 6, 3, true, false, 0, false, -1, destPath, NULL}, { DI_SINGLEBOX, 4, 5, kXMid - 2, 5 + 4, false, false, 0, false, NMessageID::kExtractPathMode, NULL, NULL }, { DI_RADIOBUTTON, 6, 6, 0, 0, false, extractionInfo.PathMode == NExtract::NPathMode::kFullPathnames, DIF_GROUP, false, NMessageID::kExtractPathFull, NULL, NULL }, { DI_RADIOBUTTON, 6, 7, 0, 0, false, extractionInfo.PathMode == NExtract::NPathMode::kCurrentPathnames, 0, false, NMessageID::kExtractPathCurrent, NULL, NULL }, { DI_RADIOBUTTON, 6, 8, 0, 0, false, extractionInfo.PathMode == NExtract::NPathMode::kNoPathnames, false, 0, NMessageID::kExtractPathNo, NULL, NULL }, { DI_SINGLEBOX, kXMid, 5, kXSize - 6, 5 + kNumOverwriteOptions, false, false, 0, false, NMessageID::kExtractOwerwriteMode, NULL, NULL }, { DI_RADIOBUTTON, kXMid + 2, 6, 0, 0, false, extractionInfo.OverwriteMode == NExtract::NOverwriteMode::kAskBefore, DIF_GROUP, false, NMessageID::kExtractOwerwriteAsk, NULL, NULL }, { DI_RADIOBUTTON, kXMid + 2, 7, 0, 0, false, extractionInfo.OverwriteMode == NExtract::NOverwriteMode::kWithoutPrompt, 0, false, NMessageID::kExtractOwerwritePrompt, NULL, NULL }, { DI_RADIOBUTTON, kXMid + 2, 8, 0, 0, false, extractionInfo.OverwriteMode == NExtract::NOverwriteMode::kSkipExisting, 0, false, NMessageID::kExtractOwerwriteSkip, NULL, NULL }, { DI_RADIOBUTTON, kXMid + 2, 9, 0, 0, false, extractionInfo.OverwriteMode == NExtract::NOverwriteMode::kAutoRename, 0, false, NMessageID::kExtractOwerwriteAutoRename, NULL, NULL }, { DI_RADIOBUTTON, kXMid + 2, 10, 0, 0, false, extractionInfo.OverwriteMode == NExtract::NOverwriteMode::kAutoRenameExisting, 0, false, NMessageID::kExtractOwerwriteAutoRenameExisting, NULL, NULL }, { DI_SINGLEBOX, 4, 10, kXMid- 2, 10 + 3, false, false, 0, false, NMessageID::kExtractFilesMode, NULL, NULL }, { DI_RADIOBUTTON, 6, 11, 0, 0, false, true, DIF_GROUP, false, NMessageID::kExtractFilesSelected, NULL, NULL }, { DI_RADIOBUTTON, 6, 12, 0, 0, false, false, 0, false, NMessageID::kExtractFilesAll, NULL, NULL }, { DI_SINGLEBOX, kXMid, kPasswordYPos, kXSize - 6, kPasswordYPos + 2, false, false, 0, false, NMessageID::kExtractPassword, NULL, NULL }, { DI_PSWEDIT, kXMid + 2, kPasswordYPos + 1, kXSize - 8, 12, false, false, 0, false, -1, oemPassword, NULL}, { DI_TEXT, 3, kYSize - 4, 0, 0, false, false, DIF_BOXCOLOR|DIF_SEPARATOR, false, -1, "", NULL }, { DI_BUTTON, 0, kYSize - 3, 0, 0, false, false, DIF_CENTERGROUP, true, NMessageID::kExtractExtract, NULL, NULL }, { DI_BUTTON, 0, kYSize - 3, 0, 0, false, false, DIF_CENTERGROUP, false, NMessageID::kExtractCancel, NULL, NULL } }; const int kNumDialogItems = sizeof(initItems) / sizeof(initItems[0]); const int kOkButtonIndex = kNumDialogItems - 2; const int kPasswordIndex = kNumDialogItems - 4; FarDialogItem dialogItems[kNumDialogItems]; g_StartupInfo.InitDialogItems(initItems, dialogItems, kNumDialogItems); for (;;) { int askCode = g_StartupInfo.ShowDialog(kXSize, kYSize, kHelpTopicExtrFromSevenZip, dialogItems, kNumDialogItems); if (askCode != kOkButtonIndex) return NFileOperationReturnCode::kInterruptedByUser; destPath = dialogItems[kPathIndex].Data; destPath.Trim(); if (destPath.IsEmpty()) { if(!NFile::NDirectory::MyGetCurrentDirectory(destPath)) throw 318016; NFile::NName::NormalizeDirPathPrefix(destPath); break; } else { if(destPath[destPath.Length() - 1] == kDirDelimiter) break; } g_StartupInfo.ShowMessage("You must specify directory path"); } if (dialogItems[kPathModeRadioIndex].Selected) extractionInfo.PathMode = NExtract::NPathMode::kFullPathnames; else if (dialogItems[kPathModeRadioIndex + 1].Selected) extractionInfo.PathMode = NExtract::NPathMode::kCurrentPathnames; else if (dialogItems[kPathModeRadioIndex + 2].Selected) extractionInfo.PathMode = NExtract::NPathMode::kNoPathnames; else throw 31806; if (dialogItems[kOverwriteModeRadioIndex].Selected) extractionInfo.OverwriteMode = NExtract::NOverwriteMode::kAskBefore; else if (dialogItems[kOverwriteModeRadioIndex + 1].Selected) extractionInfo.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt; else if (dialogItems[kOverwriteModeRadioIndex + 2].Selected) extractionInfo.OverwriteMode = NExtract::NOverwriteMode::kSkipExisting; else if (dialogItems[kOverwriteModeRadioIndex + 3].Selected) extractionInfo.OverwriteMode = NExtract::NOverwriteMode::kAutoRename; else if (dialogItems[kOverwriteModeRadioIndex + 4].Selected) extractionInfo.OverwriteMode = NExtract::NOverwriteMode::kAutoRenameExisting; else throw 31806; if (dialogItems[kFilesModeIndex].Selected) decompressAllItems = false; else if (dialogItems[kFilesModeIndex + 1].Selected) decompressAllItems = true; else throw 31806; SaveExtractionInfo(extractionInfo); if (dialogItems[kFilesModeIndex].Selected) extractSelectedFiles = true; else if (dialogItems[kFilesModeIndex + 1].Selected) extractSelectedFiles = false; else throw 31806; oemPassword = dialogItems[kPasswordIndex].Data; password = MultiByteToUnicodeString(oemPassword, CP_OEMCP); passwordIsDefined = !password.IsEmpty(); } NFile::NDirectory::CreateComplexDirectory(destPath); /* vector<int> realIndices; if (!decompressAllItems) GetRealIndexes(panelItems, itemsNumber, realIndices); */ CRecordVector<UINT32> indices; indices.Reserve(itemsNumber); for (int i = 0; i < itemsNumber; i++) indices.Add(panelItems[i].UserData); HRESULT result = ExtractFiles(decompressAllItems, &indices.Front(), itemsNumber, !showBox, extractionInfo.PathMode, extractionInfo.OverwriteMode, MultiByteToUnicodeString(destPath, CP_OEMCP), passwordIsDefined, password); // HRESULT result = ExtractFiles(decompressAllItems, realIndices, !showBox, // extractionInfo, destPath, passwordIsDefined, password); if (result != S_OK) { if (result == E_ABORT) return NFileOperationReturnCode::kInterruptedByUser; ShowErrorMessage(result); return NFileOperationReturnCode::kError; } // if(move != 0) // { // if(DeleteFiles(panelItems, itemsNumber, opMode) == FALSE) // return NFileOperationReturnCode::kError; // } return NFileOperationReturnCode::kSuccess; }
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, #ifdef UNDER_CE LPWSTR #else LPSTR #endif /* lpCmdLine */,int /* nCmdShow */) { g_hInstance = (HINSTANCE)hInstance; NT_CHECK // InitCommonControls(); UString archiveName, switches; #ifdef _SHELL_EXECUTE UString executeFile, executeParameters; #endif NCommandLineParser::SplitCommandLine(GetCommandLineW(), archiveName, switches); FString fullPath; NDLL::MyGetModuleFileName(fullPath); switches.Trim(); bool assumeYes = false; if (switches.Left(2).IsEqualToNoCase(L"-y")) { assumeYes = true; switches = switches.Mid(2, switches.Len() - 2); switches.Trim(); } AString config; if (!ReadDataString(fullPath, kStartID, kEndID, config)) { if (!assumeYes) ShowErrorMessageRes(IDS_CANT_LOAD_CONFIG_INFO); // 変更 return 1; } UString dirPrefix = L"." WSTRING_PATH_SEPARATOR; UString appLaunched; bool showProgress = true; UString friendlyName; // 追加 UString installPrompt; // 追加 bool isInstaller; // 追加 if (!config.IsEmpty()) { CObjectVector<CTextConfigPair> pairs; if (!GetTextConfig(config, pairs)) { if (!assumeYes) ShowErrorMessageRes(IDS_CONFIG_FAILED); // 変更 return 1; } friendlyName = GetTextConfigValue(pairs, L"Title"); // 変更 installPrompt = GetTextConfigValue(pairs, L"BeginPrompt"); // 変更 isInstaller = GetTextConfigValue(pairs, L"IsInstaller").IsEqualToNoCase(L"yes"); // 追加 if (isInstaller) // 追加 { // 追加 UString progress = GetTextConfigValue(pairs, L"Progress"); if (progress.IsEqualToNoCase(L"no")) showProgress = false; int index = FindTextConfigItem(pairs, L"Directory"); if (index >= 0) dirPrefix = pairs[index].String; if (!installPrompt.IsEmpty() && !assumeYes) { if (MessageBoxW(0, installPrompt, friendlyName, MB_YESNO | MB_ICONQUESTION) != IDYES) return 0; } appLaunched = GetTextConfigValue(pairs, L"RunProgram"); #ifdef _SHELL_EXECUTE executeFile = GetTextConfigValue(pairs, L"ExecuteFile"); executeParameters = GetTextConfigValue(pairs, L"ExecuteParameters") + switches; #endif } // 追加 } NFile::NDir::CTempDir tempDir; /* 追加 */ UString tempDirPath; if (isInstaller) { if (!tempDir.Create(kTempDirPrefix)) { if (!assumeYes) ShowErrorMessageRes(IDS_CANT_CREATE_TEMP_FOLDER); return 1; } tempDirPath = GetUnicodeString(tempDir.GetPath()); } else { tempDirPath = fullPath.Mid(0, fullPath.ReverseFind('\\') + 1); if (!assumeYes) { if (friendlyName.IsEmpty()) friendlyName = NWindows::MyLoadString(IDS_EXTRACT_FRIENDLY_NAME); if (installPrompt.IsEmpty()) installPrompt = NWindows::MyLoadString(IDS_EXTRACT_INSTALL_PROMPT); CExtractDialog dlg; if (dlg.Create(friendlyName, installPrompt, tempDirPath, 0) != IDOK) return 0; tempDirPath = dlg.GetFolderName(); } } /* 追加ここまで*/ /* 削除 if (!tempDir.Create(kTempDirPrefix)) { if (!assumeYes) ShowErrorMessage(L"Can not create temp folder archive"); return 1; } 削除ここまで */ CCodecs *codecs = new CCodecs; CMyComPtr<IUnknown> compressCodecsInfo = codecs; HRESULT result = codecs->Load(); if (result != S_OK) { ShowErrorMessageRes(IDS_CANT_LOAD_CODECS); // 変更 return 1; } // FString tempDirPath = tempDir.GetPath(); // 削除 { bool isCorrupt = false; UString errorMessage; HRESULT result = ExtractArchive(codecs, fullPath, tempDirPath, showProgress, isCorrupt, errorMessage); if (result != S_OK) { if (!assumeYes) { if (result == S_FALSE || isCorrupt) { errorMessage = NWindows::MyLoadString(IDS_EXTRACTION_ERROR_MESSAGE); result = E_FAIL; } if (result != E_ABORT && !errorMessage.IsEmpty()) ::MessageBoxW(0, errorMessage, NWindows::MyLoadString(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR); } return 1; } } if (!isInstaller) // 追加 return 0; // 追加 #ifndef UNDER_CE CCurrentDirRestorer currentDirRestorer; if (!NFile::NDir::SetCurrentDir(tempDir.GetPath())) return 1; #endif HANDLE hProcess = 0; #ifdef _SHELL_EXECUTE if (!executeFile.IsEmpty()) { CSysString filePath = GetSystemString(executeFile); SHELLEXECUTEINFO execInfo; execInfo.cbSize = sizeof(execInfo); execInfo.fMask = SEE_MASK_NOCLOSEPROCESS #ifndef UNDER_CE | SEE_MASK_FLAG_DDEWAIT #endif ; execInfo.hwnd = NULL; execInfo.lpVerb = NULL; execInfo.lpFile = filePath; if (!switches.IsEmpty()) executeParameters += switches; CSysString parametersSys = GetSystemString(executeParameters); if (parametersSys.IsEmpty()) execInfo.lpParameters = NULL; else execInfo.lpParameters = parametersSys; execInfo.lpDirectory = NULL; execInfo.nShow = SW_SHOWNORMAL; execInfo.hProcess = 0; /* BOOL success = */ ::ShellExecuteEx(&execInfo); UINT32 result = (UINT32)(UINT_PTR)execInfo.hInstApp; if(result <= 32) { if (!assumeYes) ShowErrorMessageRes(IDS_CANT_OPEN_FILE); // 変更 return 1; } hProcess = execInfo.hProcess; } else #endif { if (appLaunched.IsEmpty()) { appLaunched = L"setup.exe"; if (!NFile::NFind::DoesFileExist(us2fs(appLaunched))) { if (!assumeYes) ShowErrorMessageRes(IDS_CANT_FIND_SETUP); // 変更 return 1; } } { FString s2 = tempDirPath; NFile::NName::NormalizeDirPathPrefix(s2); appLaunched.Replace(L"%%T" WSTRING_PATH_SEPARATOR, fs2us(s2)); } appLaunched.Replace(L"%%T", fs2us(tempDirPath)); if (!switches.IsEmpty()) { appLaunched += L' '; appLaunched += switches; } STARTUPINFO startupInfo; startupInfo.cb = sizeof(startupInfo); startupInfo.lpReserved = 0; startupInfo.lpDesktop = 0; startupInfo.lpTitle = 0; startupInfo.dwFlags = 0; startupInfo.cbReserved2 = 0; startupInfo.lpReserved2 = 0; PROCESS_INFORMATION processInformation; CSysString appLaunchedSys = GetSystemString(dirPrefix + appLaunched); BOOL createResult = CreateProcess(NULL, (LPTSTR)(LPCTSTR)appLaunchedSys, NULL, NULL, FALSE, 0, NULL, NULL /*tempDir.GetPath() */, &startupInfo, &processInformation); if (createResult == 0) { if (!assumeYes) ShowLastErrorMessage(); return 1; } ::CloseHandle(processInformation.hThread); hProcess = processInformation.hProcess; } if (hProcess != 0) { WaitForSingleObject(hProcess, INFINITE); ::CloseHandle(hProcess); } return 0; }
CSysString CStartupInfo::GetFullKeyName(const CSysString &keyName) const { return (keyName.IsEmpty()) ? m_RegistryPath: (m_RegistryPath + kRegestryKeyDelimiter + keyName); }
int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { // Disable current directory from being in the search path. // This call does not help with implicitly loaded DLLs. if (!RemoveCurrentDirFromSearchPath()) { WCHAR minOSTitle[512] = { '\0' }; WCHAR minOSText[512] = { '\0' }; LoadStringW(NULL, IDS_MIN_OS_TITLE, minOSTitle, sizeof(minOSTitle) / sizeof(minOSTitle[0])); LoadStringW(NULL, IDS_MIN_OS_TEXT, minOSText, sizeof(minOSText) / sizeof(minOSText[0])); MessageBoxW(NULL, minOSText, minOSTitle, MB_OK | MB_ICONERROR); return 1; } g_hInstance = (HINSTANCE)hInstance; #ifndef _UNICODE g_IsNT = IsItWindowsNT(); #endif InitCommonControls(); UString archiveName, switches; #ifdef _SHELL_EXECUTE UString executeFile, executeParameters; #endif NCommandLineParser::SplitCommandLine(GetCommandLineW(), archiveName, switches); UString fullPath; NDLL::MyGetModuleFileName(g_hInstance, fullPath); switches.Trim(); bool assumeYes = false; if (switches.Left(2).CompareNoCase(UString(L"-y")) == 0) { assumeYes = true; switches = switches.Mid(2); switches.Trim(); } /* BEGIN Mozilla customizations */ bool showProgress = true; if (switches.Left(3).CompareNoCase(UString(L"-ms")) == 0 || switches.Left(4).CompareNoCase(UString(L"/INI")) == 0 || switches.Left(2).CompareNoCase(UString(L"/S")) == 0) showProgress = false; /* END Mozilla customizations */ AString config; if (!ReadDataString(fullPath, kStartID, kEndID, config)) { if (!assumeYes) MyMessageBox(L"Can't load config info"); return 1; } UString dirPrefix = L".\\"; UString appLaunched; if (!config.IsEmpty()) { CObjectVector<CTextConfigPair> pairs; if (!GetTextConfig(config, pairs)) { if (!assumeYes) MyMessageBox(L"Config failed"); return 1; } UString friendlyName = GetTextConfigValue(pairs, L"Title"); UString installPrompt = GetTextConfigValue(pairs, L"BeginPrompt"); UString progress = GetTextConfigValue(pairs, L"Progress"); if (progress.CompareNoCase(L"no") == 0) showProgress = false; int index = FindTextConfigItem(pairs, L"Directory"); if (index >= 0) dirPrefix = pairs[index].String; if (!installPrompt.IsEmpty() && !assumeYes) { if (MessageBoxW(0, installPrompt, friendlyName, MB_YESNO | MB_ICONQUESTION) != IDYES) return 0; } appLaunched = GetTextConfigValue(pairs, L"RunProgram"); #ifdef _SHELL_EXECUTE executeFile = GetTextConfigValue(pairs, L"ExecuteFile"); executeParameters = GetTextConfigValue(pairs, L"ExecuteParameters") + switches; #endif } NFile::NDirectory::CTempDirectory tempDir; if (!tempDir.Create(kTempDirPrefix)) { if (!assumeYes) MyMessageBox(L"Can not create temp folder archive"); return 1; } COpenCallbackGUI openCallback; UString tempDirPath = GetUnicodeString(tempDir.GetPath()); bool isCorrupt = false; UString errorMessage; HRESULT result = ExtractArchive(fullPath, tempDirPath, &openCallback, showProgress, isCorrupt, errorMessage); if (result != S_OK) { if (!assumeYes) { if (result == S_FALSE || isCorrupt) { errorMessage = NWindows::MyLoadStringW(IDS_EXTRACTION_ERROR_MESSAGE); result = E_FAIL; } if (result != E_ABORT && !errorMessage.IsEmpty()) ::MessageBoxW(0, errorMessage, NWindows::MyLoadStringW(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR); } return 1; } CCurrentDirRestorer currentDirRestorer; if (!SetCurrentDirectory(tempDir.GetPath())) return 1; HANDLE hProcess = 0; #ifdef _SHELL_EXECUTE if (!executeFile.IsEmpty()) { CSysString filePath = GetSystemString(executeFile); SHELLEXECUTEINFO execInfo; execInfo.cbSize = sizeof(execInfo); execInfo.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_DDEWAIT; execInfo.hwnd = NULL; execInfo.lpVerb = NULL; execInfo.lpFile = filePath; if (!switches.IsEmpty()) executeParameters += switches; CSysString parametersSys = GetSystemString(executeParameters); if (parametersSys.IsEmpty()) execInfo.lpParameters = NULL; else execInfo.lpParameters = parametersSys; execInfo.lpDirectory = NULL; execInfo.nShow = SW_SHOWNORMAL; execInfo.hProcess = 0; bool success = BOOLToBool(::ShellExecuteEx(&execInfo)); result = (UINT32)execInfo.hInstApp; if(result <= 32) { if (!assumeYes) MyMessageBox(L"Can not open file"); return 1; } hProcess = execInfo.hProcess; } else #endif { if (appLaunched.IsEmpty()) { appLaunched = L"setup.exe"; if (!NFile::NFind::DoesFileExist(GetSystemString(appLaunched))) { if (!assumeYes) MyMessageBox(L"Can not find setup.exe"); return 1; } } { UString s2 = tempDirPath; NFile::NName::NormalizeDirPathPrefix(s2); appLaunched.Replace(L"%%T\\", s2); } appLaunched.Replace(L"%%T", tempDirPath); if (!switches.IsEmpty()) { appLaunched += L' '; appLaunched += switches; } STARTUPINFO startupInfo; startupInfo.cb = sizeof(startupInfo); startupInfo.lpReserved = 0; startupInfo.lpDesktop = 0; startupInfo.lpTitle = 0; startupInfo.dwFlags = 0; startupInfo.cbReserved2 = 0; startupInfo.lpReserved2 = 0; PROCESS_INFORMATION processInformation; CSysString appLaunchedSys = GetSystemString(dirPrefix + appLaunched); BOOL createResult = CreateProcess(NULL, (LPTSTR)(LPCTSTR)appLaunchedSys, NULL, NULL, FALSE, 0, NULL, NULL /*tempDir.GetPath() */, &startupInfo, &processInformation); if (createResult == 0) { if (!assumeYes) ShowLastErrorMessage(); return 1; } ::CloseHandle(processInformation.hThread); hProcess = processInformation.hProcess; } if (hProcess != 0) { WaitForSingleObject(hProcess, INFINITE); ::CloseHandle(hProcess); } return 0; }