void ExploreFrame::OnExtractClicked( wxCommandEvent& event ) { if (m_fileListCtrl->GetSelectedItemsCount() == 0) { wxLogError(_("Select file(s) to extract")); return; } wxString extractFolder = wxStandardPaths::Get().GetDocumentsDir(); if (m_fileListCtrl->GetSelectedItemsCount() > 1) { wxDirDialog dirDlg(this, _("Select folder to extract files to"), extractFolder, wxDD_DEFAULT_STYLE); if (dirDlg.ShowModal() == wxID_OK) { wxBusyInfo busyInfo(_("Extracting data...")); wxBusyCursor busyCursor; wxDataViewItemArray selectedItems; m_fileListCtrl->GetSelections(selectedItems); for (auto it = selectedItems.begin(); it != selectedItems.end(); ++it) { const WADArchiveEntry& entry = m_archive->GetFilteredEntry((size_t) it->GetID() - 1); wxFileName targetFileName(entry.GetFileName(), wxPATH_UNIX); targetFileName.Normalize(wxPATH_NORM_ALL, dirDlg.GetPath()); wxLogDebug("Extracting to: %s", targetFileName.GetFullPath()); if (!targetFileName.Mkdir(wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL)) break; m_archive->Extract(entry, targetFileName.GetFullPath()); } } wxLogInfo(_("Files extracted to %s"), dirDlg.GetPath()); } else { const WADArchiveEntry& entry = GetSelectedEntry(); wxFileName fn(entry.GetFileName(), wxPATH_UNIX); wxString fileName = fn.GetFullName(); wxFileDialog fileDlg(this, _("Select target for file extraction"), extractFolder, fileName, wxFileSelectorDefaultWildcardStr, wxFD_OVERWRITE_PROMPT | wxFD_SAVE); if (fileDlg.ShowModal() == wxID_OK) { wxBusyInfo busyInfo(_("Extracting data...")); wxBusyCursor busyCursor; m_archive->Extract(entry, fileDlg.GetPath()); } wxLogInfo(_("File extracted to %s"), fileDlg.GetPath()); } }
void MainDialog::OnInstallConfig(wxCommandEvent &event) { wxStandardPaths stdPaths; // Get if the user has supplied a target application if(targetFileTextCtrl->GetValue().length() == 0) { wxLogError("Please select a target application first"); return; } // DT_TODO: Accept a directory as a target? // Get the target filename and directory wxFileName targetFileName(targetFileTextCtrl->GetValue()); wxString targetDirectory = targetFileName.GetPath(); if(!targetFileName.FileExists() || !wxDir::Exists(targetDirectory)) { wxLogError("Unable to find target application %s", targetFileName.GetFullPath().c_str()); return; } // Detect if there exists a appname.local file (eg. Google Earth) bool copySystemLib = false; wxFileName appLocalFile(targetFileTextCtrl->GetValue() + wxT(".local")); if(appLocalFile.FileExists()) { wxMessageDialog copySystemLibDialog(this, wxT("The target application is using a *.exe.local file.\n" "GLIntercept needs to make a copy of the system OpenGL32.dll to the target directory and set the config system lib option.\n" "Proceed?"), wxT("Copy system OpenGL?"), wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION); if(copySystemLibDialog.ShowModal() == wxID_YES) { copySystemLib = true; } } // Get the save config string wxString saveConfigString; if(!GetSaveProfileString(copySystemLib, saveConfigString)) { wxLogError("Unable to generate GLIntercept profile file data"); return; } // Calculate the source copy files wxFileName srcCopyOpenGL; srcCopyOpenGL.AssignDir(stdPaths.GetDataDir()); srcCopyOpenGL.AppendDir("MainLib"); srcCopyOpenGL.SetFullName(wxT("opengl32.dll")); // Check that the source files exist if(!srcCopyOpenGL.FileExists()) { wxLogError("Unable to copy opengl32.dll (%s) - file does not exist", srcCopyOpenGL.GetFullPath().c_str()); return; } // Calculate the destination files to copy wxFileName destCopyOpenGL(targetFileName); wxFileName destCopyConfig(targetFileName); destCopyOpenGL.SetFullName(wxT("opengl32.dll")); destCopyConfig.SetFullName(wxT("gliConfig.ini")); // Check to see if any of the writing files already exist // DT_TODO: Clean this up, looks messy when displayed wxString overwriteFilesMessage; if(destCopyOpenGL.FileExists()) { overwriteFilesMessage += wxT("\n openGL32.dll"); } if(destCopyConfig.FileExists()) { overwriteFilesMessage += wxT("\n gliConfig.ini"); } if(overwriteFilesMessage.length() > 0) { // Fill out the complete question overwriteFilesMessage = wxString(wxT("The following files already exist. Overwrite them?")) + overwriteFilesMessage; // Display the question dialog wxMessageDialog overwriteDialog(this, overwriteFilesMessage, wxT("Overwrite existing files?"), wxYES_NO | wxYES_DEFAULT | wxICON_QUESTION); if(overwriteDialog.ShowModal() == wxID_NO) { return; } } // Write the config file wxFile configWrite; if(!configWrite.Open(destCopyConfig.GetFullPath().c_str(), wxFile::write)) { wxLogError("Unable to open config file (%s)", destCopyConfig.GetFullPath().c_str()); return; } if(!configWrite.Write(saveConfigString)) { wxLogError("Unable to write to config file (%s)", destCopyConfig.GetFullPath().c_str()); return; } // Copy the GLIntercept opengl32.dll if(!::wxCopyFile(srcCopyOpenGL.GetFullPath(), destCopyOpenGL.GetFullPath())) { wxLogError("Unable to copy GLIntercept's opengl32.dll (%s)", srcCopyOpenGL.GetFullPath().c_str()); return; } //DT_TODO: If necessary, copy the system opengl32.dll to the target dir as opengl32.orig.dll //DT_TODO: Log a message : The following files have been successfully copied to ... }