private void tsbImport_Click(object sender, EventArgs e) { if (_fs == null) { return; } var ofd = new OpenFileDialog(); ofd.Title = "Import..."; if (_lastImportExportPath != null) { ofd.InitialDirectory = _lastImportExportPath; } ofd.CheckFileExists = true; ofd.CheckPathExists = true; ofd.Multiselect = true; if (ofd.ShowDialog() == DialogResult.OK) { _lastImportExportPath = IODirectory.GetParent(ofd.FileName).FullName; List <string> _invalidFiles = new List <string>(); using (new WaitCursor(this)) { for (var i = 0; i < ofd.FileNames.Length; i++) { var safename = Path.GetFileName(ofd.FileNames[i]); File file = FindFileByName(safename); if (file == null) { _invalidFiles.Add(safename); } else { byte[] data = IOFile.ReadAllBytes(ofd.FileNames[i]); file.SetData(data); } } } if (_invalidFiles.Count > 0) { var sb = new StringBuilder(); foreach (var s in _invalidFiles) { sb.Append(" " + s + "\n"); } MessageBox.Show("The following files were not found in the archive to be replaced:\n\n" + sb + "\nPlease note that you can not add new files, only replace existing ones. The files must be named exactly " + "as they are in the archive.", "Import", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } PopulateListView(); } }
protected virtual void SaveAndClose(EditorForm form, TextureFile textureFile, File file) { using (new WaitCursor(form)) { var msSave = new MemoryStream(); try { textureFile.Save(msSave); file.SetData(msSave.ToArray()); } finally { msSave.Close(); } } form.Close(); }
public void LaunchEditor(FileSystem fs, File file) { if (fs is RealFileSystem) { // We'll edit RealFileSystems on the spot... no memory caching // Some of the files are pretty big... DirectoryInfo parent = new DirectoryInfo((fs as RealFileSystem).RealDirectory).Parent; string filename = parent == null ? file.FullName : Path.Combine(parent.FullName, file.FullName); var info = new ProcessStartInfo(filename); info.UseShellExecute = true; var p = Process.Start(info); if (p != null) { p.WaitForExit(); } } else { // Export the file to a temporary file and load it up string tempFileName = Path.Combine(Path.GetTempPath(), file.Name); System.IO.File.WriteAllBytes(tempFileName, file.GetData()); var info = new ProcessStartInfo(tempFileName); info.UseShellExecute = true; var p = Process.Start(info); if (p != null) { p.WaitForExit(); if (p.ExitCode == 0) { var data = System.IO.File.ReadAllBytes(tempFileName); file.SetData(data); } } } }