void moveFilesProc(XtPointer fsel, int conf) { SelFileNamesRec *fnames = (SelFileNamesRec *) fsel; struct stat tostats, tolstats, frstats; char from[MAXPATHLEN], to[MAXPATHLEN]; String name, cwd; String op_name, from_err, to_err; size_t toend, fromend; int devto, devfrom, deverr = -1, i, perm, res; Boolean is_dir, is_link; if (conf != YES || !fnames->op) { freeSelFiles(fnames); return; } if (chdir(fnames->directory)) { sysError(fnames->shell, "System error:"); freeSelFiles(fnames); return; } chdir(user.home); switch (fnames->op) { case COPY: op_name = "Copy:"; from_err = "Error copying"; to_err = "Error copying to"; break; case MOVE: op_name = "Move:"; from_err = "Error moving"; to_err = "Error moving to"; break; default: /* i.e. LINK */ op_name = "Link:"; from_err = "Error creating symlink to"; to_err = "Error creating symlink in"; } if (fnames->target[0] != '/' && fnames->target[0] != '~' && fnames->target != 0) { strcpy(to, fnames->directory); if (to[strlen(to)-1] != '/') strcat(to, "/"); } else to[0] = 0; strcat(to, fnames->target); fnexpand(to); if (!(cwd = absolutePath(to))) { error(fnames->shell, no_target, to); freeSelFiles(fnames); return; } strcpy(to, cwd); XTFREE(cwd); fromend = strlen(strcpy(from, fnames->directory)); if (from[fromend-1] != '/') { from[fromend++] = '/'; from[fromend] = 0; } devfrom = findDev(from); if (mountDev(devto = findDev(to), False)) deverr = devto; else if (mountDev(devfrom, False)) deverr = devfrom; if (deverr != -1) { error(fnames->shell, "Cannot mount device on", mntable.devices[deverr].def_mpoint); umountDev(devto, False); freeSelFiles(fnames); return; } if (!(stat(to, &tostats)) && S_ISDIR(tostats.st_mode)) { if (chdir(to) || !(perm = permission(&tostats, P_WRITE))) { chdir(user.home); if (!perm) error(fnames->shell, "You have no write permission for ", to); else sysError(fnames->shell, "System error:"); umountDev(devto, False); umountDev(devfrom, False); freeSelFiles(fnames); return; } chdir(user.home); fnames->dirtarget = True; toend = strlen(to); if (to[toend-1] != '/') { to[toend++] = '/'; to[toend] = 0; } } else if (fnames->n_sel == 1) fnames->dirtarget = False; else { error(fnames->shell, op_name, "Target for multiple files must be a folder"); umountDev(devto, False); umountDev(devfrom, False); freeSelFiles(fnames); return; } if (!fnames->first) zzz(); XTFREE(fnames->target); fnames->target = XtNewString(to); for (i = fnames->first; i < fnames->n_sel; i++) { name = fnames->names[i]; if (fnames->op != LINK && (!strcmp(name, ".") || !strcmp(name, ".."))) { error(fnames->shell, "Cannot move or copy . or ..", NULL); continue; } strcpy(from+fromend, name); if (fnames->dirtarget) { if (fnames->op != LINK && prefix(from, to)) { String err_str, format = "Cannot move or copy %s to"; err_str = (String) XtMalloc((strlen(format) + strlen(from)) * sizeof(char)); sprintf(err_str, format, from); error(fnames->shell, err_str, to); XTFREE(err_str); umountDev(devto, False); umountDev(devfrom, False); freeSelFiles(fnames); wakeUp(); return; } strcpy(to+toend, name); } if (!(lstat(to, &tolstats))) { fnames->first = i; is_dir = False; if (!(stat(to, &tostats))) { if (S_ISDIR(tostats.st_mode)) is_dir = True; if (!stat(from, &frstats) && tostats.st_ino == frstats.st_ino) { error(fnames->shell, op_name, "Source and destination are identical"); umountDev(devto, False); umountDev(devfrom, False); freeSelFiles(fnames); wakeUp(); return; } } if (S_ISLNK(tolstats.st_mode)) is_link = True; else is_link = False; if (fnames->conf_ovwr || (is_dir && (!is_link || fnames->op == COPY) && resources.confirm_delete_folder)) overwriteDialog(fnames, to, (fnames->op == COPY && is_dir && (lstat(from, &frstats) || !S_ISDIR(frstats.st_mode)))? "File copy:" : op_name, is_dir && (!is_link || fnames->op == COPY)); else overwriteProc(fsel, YES); umountDev(devto, False); umountDev(devfrom, False); return; } switch (fnames->op) { case COPY: rcopy(from, to, False); res = 0; break; case MOVE: res = movefile(from, to); break; default: res = makeLink(from, to); } if (res) { if (opError(fnames->shell, from_err, name) != YES) break; } else fnames->update = True; } umountDev(devto, False); umountDev(devfrom, False); if (fnames->update) { if (fnames->op == COPY) intUpdate(CHECK_DIR); /* Check for new subdirectories */ if (fnames->op == MOVE) markForUpdate(fnames->directory, CHECK_FILES); markForUpdate(to, RESHOW); if (fnames->op != COPY) intUpdate(CHECK_DIR); } freeSelFiles(fnames); wakeUp(); }
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 ... }