public override void LaunchEditor(FileSystem fs, File file) { var data = file.GetData(); var ms = new MemoryStream(data); var hyperTextFile = new HyperTextFile(); try { hyperTextFile.Open(ms); } finally { ms.Close(); } if (hyperTextFile.EmbeddedTextureFile != null) { ShowForm(file, hyperTextFile.EmbeddedTextureFile); } else { MessageBox.Show("There are no embedded textures in the selected HyperText file to edit.", "Edit", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public override void LaunchEditor(FileSystem fs, File file) { var data = file.GetData(); var ms = new MemoryStream(data); var modelFile = new ModelFile(); try { modelFile.Open(ms); } finally { ms.Close(); } if (modelFile.EmbeddedTextureFile != null) { ShowForm(file, modelFile.EmbeddedTextureFile); } else { MessageBox.Show("There are no embedded textures in the selected model file to edit.", "Edit", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public static bool HasViewer(File file) { var fileName = file.Name; var extension = fileName.Substring(fileName.LastIndexOf('.') + 1); return _viewers.ContainsKey(extension); }
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(); } }
private void PreviewOrEditFile(File file) { if (Viewers.HasViewer(file)) { PreviewFile(file); } else if (Editors.HasEditor(file)) { EditFile(file); } }
public void LaunchEditor(FileSystem fs, File file) { if (fs is RealFileSystem) { var form = new MainForm(); form.Show(); DirectoryInfo parent = new DirectoryInfo((fs as RealFileSystem).RealDirectory).Parent; string archiveFilename = parent == null ? file.FullName : Path.Combine(parent.FullName, file.FullName); form.OpenFile(archiveFilename, null); } }
private File FindFileByName(string name) { foreach (var fsObject in _selectedDir) { File file = fsObject as File; if (file != null) { if (file.Name.ToLower() == name.ToLower()) { return(file); } } } return(null); }
private void PreviewFile(File file) { if (Viewers.HasViewer(file)) { Control viewerControl = Viewers.GetControl(file); if (viewerControl != null) { using (var form = new ViewerForm()) { form.SetFilename(file.Name); form.SetControl(viewerControl); form.ShowDialog(); } } } }
public static Control GetControl(File file) { var fileName = file.Name; var extension = fileName.Substring(fileName.LastIndexOf('.') + 1); if (_viewers.ContainsKey(extension)) { var control = _viewers[extension].GetView(file); if (control != null) { return control; } } return null; }
public Control GetView(File file) { var data = file.GetData(); TextBox textBox = new TextBox(); textBox.Font = new Font("Courier New", 10); textBox.ReadOnly = true; textBox.BackColor = SystemColors.Window; textBox.Text = Encoding.ASCII.GetString(data); textBox.Multiline = true; textBox.ScrollBars = ScrollBars.Both; textBox.SelectionStart = 0; textBox.SelectionLength = 0; textBox.WordWrap = false; return textBox; }
public virtual void LaunchEditor(FileSystem fs, File file) { var data = file.GetData(); var ms = new MemoryStream(data); var textureFile = new TextureFile(); try { textureFile.Open(ms); } finally { ms.Close(); } ShowForm(file, textureFile); }
private void EditFile(File file) { if (Editors.HasEditor(file)) { Editors.LaunchEditor(_fs, file); if (file.IsCustomData) { foreach (ListViewItem item in lvFiles.Items) { if (item.Tag == file) { item.ForeColor = CustomDataForeColor; break; } } } } }
public static bool HasEditor(File file) { var fileName = file.Name; var extension = fileName.Substring(fileName.LastIndexOf('.') + 1); bool hasEditor = _editors.ContainsKey(extension); if (!hasEditor && _editors.ContainsKey("")) { var dynamicEditor = _editors[""] as IDynamicEditor; if (dynamicEditor != null) { hasEditor = dynamicEditor.SupportsExtension(extension); } } return hasEditor; }
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); } } } }
public static void LaunchEditor(FileSystem fs, File file) { var fileName = file.Name; var extension = fileName.Substring(fileName.LastIndexOf('.') + 1); if (_editors.ContainsKey(extension)) { var editor = _editors[extension]; editor.LaunchEditor(fs, file); } else { var editor = _editors[""]; if (editor != null) { editor.LaunchEditor(fs, file); } } }
protected void ShowForm(File file, TextureFile textureFile) { var view = new TextureEditView(); var controller = new TextureEditController(view); controller.TextureFile = textureFile; using (var form = new EditorForm()) { form.SetFilename(file.Name); form.SetControl(view); controller.SaveAndClose += ((sender, e) => SaveAndClose(form, textureFile, file)); form.ShowDialog(); } textureFile.Dispose(); }
private void ExtractToPath(Directory dir, string path) { foreach (var item in dir) { if (item.IsDirectory) { try { IODirectory.CreateDirectory(path + item.Name); ExtractToPath(item as Directory, path + item.Name + "\\"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { File file = item as File; byte[] data = file.GetData(); IOFile.WriteAllBytes(Path.Combine(path, file.Name), data); } } }
private void PopulateListView() { // Redisable some buttons (will be autoenabled based on selection) tsbPreview.Enabled = false; tsbEdit.Enabled = false; Directory dir = _selectedDir; string filterString = tstFilterBox.Text; List <string> selectedFileNames = new List <string>(); foreach (var o in lvFiles.SelectedItems) { selectedFileNames.Add((o as ListViewItem).Text); } var comparer = lvFiles.ListViewItemSorter; lvFiles.ListViewItemSorter = null; lvFiles.BeginUpdate(); lvFiles.Items.Clear(); using (new WaitCursor(this)) { foreach (var item in dir) { if (!item.IsDirectory) { File file = item as File; if (filterString == "" || file.Name.IndexOf(filterString) > -1) { ListViewItem lvi = lvFiles.Items.Add(file.Name); lvi.Tag = file; lvi.SubItems.Add(FriendlySize(file.Size)); /* * string compressed = file.IsCompressed ? "Yes (" + FriendlySize(file.CompressedSize) + ")" : "No"; * lvi.SubItems.Add(compressed); */ string resources = file.IsResource ? "Yes" : "No"; if (file.IsResource) { string rscType = Enum.IsDefined(file.ResourceType.GetType(), file.ResourceType) ? file.ResourceType.ToString() : string.Format("Unknown 0x{0:x}", (int)file.ResourceType); resources += " (" + rscType + ")"; } lvi.SubItems.Add(resources); if (file.IsCustomData) { lvi.ForeColor = CustomDataForeColor; } if (selectedFileNames.Contains(file.Name)) { lvi.Selected = true; } } } } } lvFiles.EndUpdate(); lvFiles.ListViewItemSorter = comparer; lvFiles.Sort(); }
private void tsbExportSelected_Click(object sender, EventArgs e) { if (_fs == null) { return; } if (lvFiles.SelectedItems.Count == 1) { File file = lvFiles.SelectedItems[0].Tag as File; SaveFileDialog sfd = new SaveFileDialog(); sfd.Title = "Export..."; if (_lastImportExportPath != null) { sfd.InitialDirectory = _lastImportExportPath; sfd.FileName = Path.Combine(_lastImportExportPath, file.Name); } else { sfd.FileName = file.Name; } sfd.OverwritePrompt = true; if (sfd.ShowDialog() == DialogResult.OK) { _lastImportExportPath = IODirectory.GetParent(sfd.FileName).FullName; using (new WaitCursor(this)) { byte[] data = file.GetData(); IOFile.WriteAllBytes(sfd.FileName, data); } } } else if (lvFiles.SelectedItems.Count > 1) { FolderBrowserDialog fbd = new FolderBrowserDialog(); fbd.Description = "Export Selected..."; fbd.ShowNewFolderButton = true; fbd.SelectedPath = _lastImportExportPath; if (fbd.ShowDialog() == DialogResult.OK) { _lastImportExportPath = fbd.SelectedPath; string path = fbd.SelectedPath; using (new WaitCursor(this)) { foreach (ListViewItem item in lvFiles.SelectedItems) { File file = item.Tag as File; byte[] data = file.GetData(); IOFile.WriteAllBytes(Path.Combine(path, file.Name), data); } } MessageBox.Show("All selected files exported.", "Export Selected", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }