bool TestArchive(const std::list<CString> &rArcList,CConfigManager &ConfigManager) { CArchiverDLLManager &ArchiverManager=CArchiverDLLManager::GetInstance(); //XacRettはチェックが甘いため使わない //プログレスバー CProgressDialog dlg; int nFiles=rArcList.size(); dlg.Create(NULL); dlg.SetTotalFileCount(nFiles); dlg.ShowWindow(SW_SHOW); std::list<CString>::const_iterator ite=rArcList.begin(); const std::list<CString>::const_iterator end=rArcList.end(); //テスト結果を格納する std::vector<ARCLOG> LogArray; for(;ite!=end;++ite){ //プログレスバーを進める if(dlg.IsWindow())dlg.SetNextState(*ite); ARCLOG arcLog; arcLog.strFile=*ite; //アーカイバハンドラ取得 //NOTE:DenyExtによる対象絞り込みは既に行われているので2回は行わない CArchiverDLL *Archiver=ArchiverManager.GetArchiver(*ite,NULL); if(!Archiver){ //---対応するハンドラがなかった:原因を調査 //通常のエラー arcLog.strMsg.Format(IDS_ERROR_ILLEGAL_HANDLER,*ite); arcLog.Result=TEST_NOTARCHIVE; //UNICODE関係のチェック if(!UtilCheckT2A(*ite)){ //UNICODEに対応していないのにUNICODEファイル名のファイルを扱おうとした arcLog.strMsg+=_T("\r\n\r\n"); arcLog.strMsg.AppendFormat(IDS_ERROR_UNICODEPATH); } }else{ CString strTemp; arcLog.Result=Archiver->TestArchive(*ite,strTemp); arcLog.strMsg=Archiver->GetName(); arcLog.strMsg+=_T("\r\n\r\n"); arcLog.strMsg+=strTemp; } LogArray.push_back(arcLog); } //プログレスバーを閉じる if(dlg.IsWindow())dlg.DestroyWindow(); //ログに表示 CLogListDialog LogDlg(CString(MAKEINTRESOURCE(IDS_LOGINFO_OPERATION_TESTARCHIVE))); LogDlg.SetLogArray(LogArray); LogDlg.DoModal(::GetDesktopWindow()); return true; }
void testCProgressDialog() { CProgressDialog ProgressDialog; CThreadProgressDialog benchmarker; benchmarker.ProgressDialog = &ProgressDialog; NWindows::CThread thread; thread.Create(CThreadProgressDialog::MyThreadFunction, &benchmarker); // void StartProgressDialog(const UString &title) int ret = ProgressDialog.Create(L"testCProgressDialog", 0); if (ret == IDOK) myErrorMsg(wxT("CProgressDialog => IDOK")); else if (ret == IDCANCEL) myErrorMsg(wxT("CProgressDialog => IDCANCEL")); else myErrorMsg(wxT("CProgressDialog => ?")); }
void CApp::Combine() { int srcPanelIndex = GetFocusedPanelIndex(); CPanel &srcPanel = Panels[srcPanelIndex]; if (!srcPanel.IsFSFolder()) { srcPanel.MessageBox(LangString(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208)); return; } CRecordVector<UInt32> indices; srcPanel.GetOperatedItemIndices(indices); if (indices.IsEmpty()) return; int index = indices[0]; if (indices.Size() != 1 || srcPanel.IsItemFolder(index)) { srcPanel.MessageBox(LangString(IDS_COMBINE_SELECT_ONE_FILE, 0x03020620)); return; } const UString itemName = srcPanel.GetItemName(index); UString srcPath = srcPanel._currentFolderPrefix + srcPanel.GetItemPrefix(index); UString path = srcPath; int destPanelIndex = (NumPanels <= 1) ? srcPanelIndex : (1 - srcPanelIndex); CPanel &destPanel = Panels[destPanelIndex]; if (NumPanels > 1) if (destPanel.IsFSFolder()) path = destPanel._currentFolderPrefix; CCopyDialog copyDialog; copyDialog.Value = path; copyDialog.Title = LangString(IDS_COMBINE, 0x03020600); copyDialog.Title += ' '; copyDialog.Title += srcPanel.GetItemRelPath(index); copyDialog.Static = LangString(IDS_COMBINE_TO, 0x03020601);; if (copyDialog.Create(srcPanel.GetParent()) == IDCANCEL) return; CThreadCombine combiner; // combiner.Panel = this; { CProgressDialog progressDialog; combiner.ProgressDialog = &progressDialog; UString progressWindowTitle = LangString(IDS_APP_TITLE, 0x03000000); UString title = LangString(IDS_COMBINING, 0x03020610); progressDialog.MainWindow = _window; progressDialog.MainTitle = progressWindowTitle; progressDialog.MainAddTitle = title + UString(L" "); path = copyDialog.Value; NFile::NName::NormalizeDirPathPrefix(path); if (!NFile::NDirectory::CreateComplexDirectory(path)) { srcPanel.MessageBoxMyError(MyFormatNew(IDS_CANNOT_CREATE_FOLDER, 0x02000603, path)); return; } combiner.InputDirPrefix = srcPath; combiner.FirstVolumeName = itemName; combiner.OutputDirPrefix = path; // CPanel::CDisableTimerProcessing disableTimerProcessing1(srcPanel); // CPanel::CDisableTimerProcessing disableTimerProcessing2(destPanel); NWindows::CThread thread; if (thread.Create(CThreadCombine::MyThreadFunction, &combiner) != S_OK) throw 271824; progressDialog.Create(title, _window); } RefreshTitleAlways(); if (!combiner.Error.IsEmpty()) srcPanel.MessageBoxMyError(combiner.Error); // disableTimerProcessing1.Restore(); // disableTimerProcessing2.Restore(); // srcPanel.SetFocusToList(); // srcPanel.RefreshListCtrlSaveFocused(); }
bool Extract(std::list<CString> &ParamList,CConfigManager &ConfigManager,DLL_ID ForceDLL,LPCTSTR lpSpecificOutputDir,const CMDLINEINFO* lpCmdLineInfo) { TRACE(_T("Function ::Extract() started.\n")); CConfigGeneral ConfGeneral; CConfigExtract ConfExtract; ConfGeneral.load(ConfigManager); ConfExtract.load(ConfigManager); //設定上書き if(lpCmdLineInfo){ if(-1!=lpCmdLineInfo->OutputToOverride){ ConfExtract.OutputDirType=lpCmdLineInfo->OutputToOverride; } if(-1!=lpCmdLineInfo->CreateDirOverride){ ConfExtract.CreateDir=lpCmdLineInfo->CreateDirOverride; } if(-1!=lpCmdLineInfo->DeleteAfterProcess){ ConfExtract.DeleteArchiveAfterExtract=lpCmdLineInfo->DeleteAfterProcess; } } //セマフォによる排他処理 CSemaphoreLocker SemaphoreLock; if(ConfExtract.LimitExtractFileCount){ SemaphoreLock.Lock(LHAFORGE_EXTRACT_SEMAPHORE_NAME,ConfExtract.MaxExtractFileCount); } UINT uFiles=ParamList.size(); //引数にあるファイルの数 //プログレスバー CProgressDialog dlg; //メッセージループを回すためのタイマー int timer=NULL; if(uFiles>=2){ //ファイルが複数ある時に限定 dlg.Create(NULL); dlg.SetTotalFileCount(uFiles); dlg.ShowWindow(SW_SHOW); timer=SetTimer(NULL,NULL,1000,UtilMessageLoopTimerProc); } //指定の出力先 CPath pathSpecificOutputDir(lpSpecificOutputDir ? lpSpecificOutputDir : _T("")); std::vector<ARCLOG> LogArray; //処理結果を保持 bool bAllOK=true; //すべて問題なく解凍されればtrue //解凍処理 for(std::list<CString>::iterator ite_param=ParamList.begin();ite_param!=ParamList.end();++ite_param){ //プログレスバーを進める if(dlg.IsWindow())dlg.SetNextState(*ite_param); ARCLOG arcLog; //メッセージループ while(UtilDoMessageLoop())continue; //アーカイバハンドラ取得 //ここでUNICODE非対応DLLにユニコードファイル名を渡そうとした場合は弾かれる。そして、ここでは失敗の原因を解明できない CArchiverDLL *lpArchiver=CArchiverDLLManager::GetInstance().GetArchiver(*ite_param,ConfExtract.DenyExt,ForceDLL); if(!lpArchiver){ //対応するハンドラがなかった arcLog.Result=EXTRACT_NOTARCHIVE; arcLog.strMsg.Format(IDS_ERROR_ILLEGAL_HANDLER,(LPCTSTR)*ite_param); arcLog.strFile=*ite_param; bAllOK=false; LogArray.push_back(arcLog); continue; } CPath pathOpenDir; //ファイラが開くべきフォルダ //解凍実行 bool bRet=ExtractOneArchive(ConfigManager,ConfGeneral,ConfExtract,lpArchiver,*ite_param,pathSpecificOutputDir,arcLog,pathOpenDir); //ログ保存 LogArray.push_back(arcLog); if(!bRet){ bAllOK=false; }else{ //出力先フォルダを開く if(ConfExtract.OpenDir){ if(ConfGeneral.Filer.UseFiler){ //パラメータ展開に必要な情報 std::map<stdString,CString> envInfo; MakeExpandInformationEx(envInfo,pathOpenDir,NULL); //コマンド・パラメータ展開 CString strCmd,strParam; UtilExpandTemplateString(strCmd,ConfGeneral.Filer.FilerPath,envInfo); //コマンド UtilExpandTemplateString(strParam,ConfGeneral.Filer.Param,envInfo); //パラメータ ShellExecute(NULL, _T("open"), strCmd,strParam, NULL, SW_SHOWNORMAL); }else{ //Explorerで開く UtilNavigateDirectory(pathOpenDir); } } //正常に解凍できた圧縮ファイルを削除orごみ箱に移動 if(bRet && ConfExtract.DeleteArchiveAfterExtract){ if(!ConfExtract.ForceDelete && lpArchiver->IsWeakErrorCheck()){ //エラーチェック機構が貧弱なため、解凍失敗時にも正常と判断してしまうような //DLLを使ったときには明示的に指定しない限り削除させない MessageBox(NULL,CString(MAKEINTRESOURCE(IDS_MESSAGE_EXTRACT_DELETE_SKIPPED)),UtilGetMessageCaption(),MB_OK|MB_ICONINFORMATION); }else{ //削除 DeleteOriginalArchives(ConfExtract,*ite_param); } } } } //プログレスバーを閉じる if(dlg.IsWindow())dlg.DestroyWindow(); //タイマーを閉じる if(timer)KillTimer(NULL,timer); //---ログ表示 switch(ConfGeneral.LogViewEvent){ case LOGVIEW_ON_ERROR: if(!bAllOK){ if(1==uFiles){ //ファイル一つだけの時はダイアログボックスで if(EXTRACT_CANCELED!=LogArray[0].Result){ ErrorMessage(LogArray[0].strMsg); } }else{ //ログに表示 CLogListDialog LogDlg(CString(MAKEINTRESOURCE(IDS_LOGINFO_OPERATION_EXTRACT))); LogDlg.SetLogArray(LogArray); LogDlg.DoModal(::GetDesktopWindow()); } } break; case LOGVIEW_ALWAYS: //ログに表示 CLogListDialog LogDlg(CString(MAKEINTRESOURCE(IDS_LOGINFO_OPERATION_EXTRACT))); LogDlg.SetLogArray(LogArray); LogDlg.DoModal(::GetDesktopWindow()); break; } TRACE(_T("Exit Extract()\n")); return bAllOK; }
void CApp::Split() { int srcPanelIndex = GetFocusedPanelIndex(); CPanel &srcPanel = Panels[srcPanelIndex]; if (!srcPanel.IsFSFolder()) { srcPanel.MessageBox(LangString(IDS_OPERATION_IS_NOT_SUPPORTED, 0x03020208)); return; } CRecordVector<UInt32> indices; srcPanel.GetOperatedItemIndices(indices); if (indices.IsEmpty()) return; if (indices.Size() != 1) { srcPanel.MessageBox(L"Select one file"); return; } int index = indices[0]; if (srcPanel.IsItemFolder(index)) { srcPanel.MessageBox(L"Select one file"); return; } const UString itemName = srcPanel.GetItemName(index); UString srcPath = srcPanel._currentFolderPrefix + srcPanel.GetItemPrefix(index); UString path = srcPath; int destPanelIndex = (NumPanels <= 1) ? srcPanelIndex : (1 - srcPanelIndex); CPanel &destPanel = Panels[destPanelIndex]; if (NumPanels > 1) if (destPanel.IsFSFolder()) path = destPanel._currentFolderPrefix; CSplitDialog splitDialog; splitDialog.FilePath = srcPanel.GetItemRelPath(index); splitDialog.Path = path; if (splitDialog.Create(srcPanel.GetParent()) == IDCANCEL) return; NFile::NFind::CFileInfoW fileInfo; if (!NFile::NFind::FindFile(srcPath + itemName, fileInfo)) { srcPanel.MessageBoxMyError(L"Can not find file"); return; } if (fileInfo.Size <= splitDialog.VolumeSizes.Front()) { srcPanel.MessageBoxMyError(LangString(IDS_SPLIT_VOL_MUST_BE_SMALLER, 0x03020522)); return; } const UInt64 numVolumes = GetNumberOfVolumes(fileInfo.Size, splitDialog.VolumeSizes); if (numVolumes >= 100) { wchar_t s[32]; ConvertUInt64ToString(numVolumes, s); if (::MessageBoxW(srcPanel, MyFormatNew(IDS_SPLIT_CONFIRM_MESSAGE, 0x03020521, s), LangString(IDS_SPLIT_CONFIRM_TITLE, 0x03020520), MB_YESNOCANCEL | MB_ICONQUESTION | MB_TASKMODAL) != IDYES) return; } path = splitDialog.Path; NFile::NName::NormalizeDirPathPrefix(path); if (!NFile::NDirectory::CreateComplexDirectory(path)) { srcPanel.MessageBoxMyError(MyFormatNew(IDS_CANNOT_CREATE_FOLDER, 0x02000603, path)); return; } CThreadSplit spliter; // spliter.Panel = this; { CProgressDialog progressDialog; spliter.ProgressDialog = &progressDialog; UString progressWindowTitle = LangString(IDS_APP_TITLE, 0x03000000); UString title = LangString(IDS_SPLITTING, 0x03020510); progressDialog.MainWindow = _window; progressDialog.MainTitle = progressWindowTitle; progressDialog.MainAddTitle = title + UString(L" "); progressDialog.ProgressSynch.SetTitleFileName(itemName); spliter.FilePath = srcPath + itemName; spliter.VolBasePath = path + itemName; spliter.VolumeSizes = splitDialog.VolumeSizes; // if (splitDialog.VolumeSizes.Size() == 0) return; // CPanel::CDisableTimerProcessing disableTimerProcessing1(srcPanel); // CPanel::CDisableTimerProcessing disableTimerProcessing2(destPanel); NWindows::CThread thread; if (thread.Create(CThreadSplit::MyThreadFunction, &spliter) != S_OK) throw 271824; progressDialog.Create(title, _window); } RefreshTitleAlways(); if (!spliter.Error.IsEmpty()) srcPanel.MessageBoxMyError(spliter.Error); // disableTimerProcessing1.Restore(); // disableTimerProcessing2.Restore(); // srcPanel.SetFocusToList(); // srcPanel.RefreshListCtrlSaveFocused(); }