public ProfilePorter(ProfileManager profiles, MainForm mainForm, Stream data) : this(profiles, true, mainForm) { inputFile = new ZipFile(data); }
public ProfilePorter(ProfileManager profiles, string file, MainForm mainForm) : this(profiles, true, mainForm) { this.inputFileName = file; }
private void ProfileExporter_Load(object sender, EventArgs e) { if (!importMode) { profileListBox.DataSource = profiles.AllProfileNames; return; } if (inputFile == null) { if (string.IsNullOrEmpty(inputFileName)) { OpenFileDialog inputChooser = new OpenFileDialog(); inputChooser.Filter = "Zip archives|*.zip"; inputChooser.Title = "Select your input file"; if (inputChooser.ShowDialog() != DialogResult.OK) { Close(); return; } inputFileName = inputChooser.FileName; } try { inputFile = new ZipFile(File.OpenRead(inputFileName)); } catch (IOException ioe) { MessageBox.Show( string.Format("Error opening selected file: {0}{1}{0}Import cancelled", Environment.NewLine, ioe.Message), "Error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } } foreach (ZipEntry entry in inputFile) { string pathname = Path.Combine(path, entry.Name); if (entry.IsDirectory) { Directory.CreateDirectory(pathname); } else // entry.isFile { System.Diagnostics.Debug.Assert(entry.IsFile); FileUtil.ensureDirectoryExists(Path.GetDirectoryName(pathname)); Stream outputStream = File.OpenWrite(pathname); FileUtil.copyData(inputFile.GetInputStream(entry), outputStream); outputStream.Close(); } } inputFile.Close(); inputFile = null; importedProfiles = new ProfileManager(path); importedProfiles.LoadProfiles(); #region old code /* * XmlSerializer videoSerializer, audioSerializer, avsSerializer, oneclickSerializer; * videoSerializer = new XmlSerializer(typeof(GenericProfile<VideoCodecSettings>)); * audioSerializer = new XmlSerializer(typeof(GenericProfile<AudioCodecSettings>)); * avsSerializer = new XmlSerializer(typeof(GenericProfile<AviSynthSettings>)); * oneclickSerializer = new XmlSerializer(typeof(GenericProfile<OneClickSettings>)); * #warning We are generating a list of failed attempts, but we aren't doing anything with it (below). * List<string> failedEntries = new List<string>(); * foreach (ZipEntry entry in inputFile) * { * // Check if the entry is in the video/audio/avs/oneclick/extra folders. * // Try to deserialize if it is a profile, list the files in the extra folders #region terribly boring cases * if (entry.IsFile) * { * if (entry.Name.ToLower().StartsWith("profiles\\video") || entry.Name.ToLower().StartsWith("profiles/video")) || { || try || { || importedProfiles.AddVideoProfile( || (GenericProfile<VideoCodecSettings>)videoSerializer.Deserialize(inputFile.GetInputStream(entry))); || } || catch (Exception) || { || failedEntries.Add(entry.Name); || } || } || || else if (entry.Name.ToLower().StartsWith("profiles\\audio") || entry.Name.ToLower().StartsWith("profiles/audio")) || { || try || { || importedProfiles.AddProfile( || (GenericProfile<AudioCodecSettings>)audioSerializer.Deserialize(inputFile.GetInputStream(entry))); || } || catch (Exception) || { || failedEntries.Add(entry.Name); || } || } || || else if (entry.Name.ToLower().StartsWith("profiles\\avs") || entry.Name.ToLower().StartsWith("profiles/avs")) || { || try || { || importedProfiles.AddProfile( || (GenericProfile<AviSynthSettings>)avsSerializer.Deserialize(inputFile.GetInputStream(entry))); || } || catch (Exception) || { || failedEntries.Add(entry.Name); || } || } || || else if (entry.Name.ToLower().StartsWith("profiles\\oneclick") || entry.Name.ToLower().StartsWith("profiles/oneclick")) || { || try || { || importedProfiles.AddProfile( || (GenericProfile<OneClickSettings>)oneclickSerializer.Deserialize(inputFile.GetInputStream(entry))); || } || catch (Exception) || { || failedEntries.Add(entry.Name); || } || } || else if (entry.Name.ToLower().StartsWith("extra\\") || entry.Name.ToLower().StartsWith("extra/")) || { || extraFiles.Add(entry.Name, entry); || } || } #endregion ||} */ #endregion profileListBox.DataSource = importedProfiles.AllProfileNames; }
private void okButton_Click(object sender, EventArgs e) { if (importMode) { moveProfiles(importedProfiles, profiles); } else { // Choose output filename SaveFileDialog outputFilesChooser = new SaveFileDialog(); outputFilesChooser.Title = "Choose your output file"; outputFilesChooser.Filter = "Zip archives|*.zip"; if (outputFilesChooser.ShowDialog() != DialogResult.OK) { return; } string filename = outputFilesChooser.FileName; // This outputfile is accessed by moveProfiles, so must be initialised beforehand outputFile = new ZipOutputStream(File.OpenWrite(filename)); ProfileManager to = new ProfileManager(path); moveProfiles(profiles, to); to.SaveProfiles(); foreach (string file in FileUtil.AllFiles(path)) { ZipEntry newEntry = new ZipEntry(file.Substring(path.Length).TrimStart('\\', '/')); outputFile.PutNextEntry(newEntry); FileStream input = File.OpenRead(file); FileUtil.copyData(input, outputFile); input.Close(); } outputFile.Close(); MessageBox.Show("Completed successfully", "Export completed successfully", MessageBoxButtons.OK, MessageBoxIcon.Information); } #if UNUSED if (importMode) { // Gather the list of selected profiles and convert them to strings IList list_selectedProfiles = profileListBox.SelectedItems; int i = 0; string[] selectedProfiles = new string[list_selectedProfiles.Count]; foreach (object o in list_selectedProfiles) { selectedProfiles[i] = (string)o; i++; } // List the profiles to be imported Profile[] profileList = importedProfiles.AllProfiles(selectedProfiles); // List the extra files to be copied List <string> fileList = importedProfiles.AllRequiredFiles(profileList); // Copy the files and store where they have been moved to (in the substitution table) #region copying Dictionary <string, string> substitutionTable = new Dictionary <string, string>(); foreach (string file in fileList) { string filename = Path.GetFileName(file); string pathname = mainForm.MeGUIPath + "\\extra\\" + filename; int count = 0; while (File.Exists(pathname)) { pathname = mainForm.MeGUIPath + "\\extra\\" + count + "_" + filename; count++; } substitutionTable[file] = pathname; /* if (substitutionTable.ContainsKey(file)) * substitutionTable.Remove(file); * substitutionTable.Add(file, pathname);*/ try { if (!Directory.Exists(mainForm.MeGUIPath + "\\extra")) { Directory.CreateDirectory(mainForm.MeGUIPath + "\\extra"); } Stream outputStream = File.OpenWrite(pathname); copyData(inputFile.GetInputStream(extraFiles[file]), outputStream); outputStream.Close(); } catch (IOException ioe) { MessageBox.Show( string.Format("Error opening selected file: {0}{1}{0}Import cancelled", Environment.NewLine, ioe.Message), "Error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } } #endregion // Fix up the filenames with the substitution table ProfileManager.FixFileNames(profileList, substitutionTable); // Add the profiles to the main manager profiles.AddAll(profileList, mainForm.DialogManager); this.Close(); } else // export mode { // Choose output filename SaveFileDialog outputFilesChooser = new SaveFileDialog(); outputFilesChooser.Title = "Choose your output file"; outputFilesChooser.Filter = "Zip archives|*.zip"; if (outputFilesChooser.ShowDialog() != DialogResult.OK) { return; } string filename = outputFilesChooser.FileName; // List profile names IList list_selectedProfiles = profileListBox.SelectedItems; int i = 0; string[] selectedProfiles = new string[list_selectedProfiles.Count]; foreach (object o in list_selectedProfiles) { selectedProfiles[i] = (string)o; i++; } // List profiles Profile[] profileList = profiles.AllProfiles(selectedProfiles); Dictionary <string, string> substitutionTable = new Dictionary <string, string>(); Dictionary <string, string> fileList = profiles.AllRequiredFiles(profileList, out substitutionTable); ProfileManager.FixFileNames(profileList, substitutionTable); ZipOutputStream outputFile = new ZipOutputStream(File.OpenWrite(filename)); foreach (string zipFilename in fileList.Keys) { ZipEntry newEntry = new ZipEntry(zipFilename); outputFile.PutNextEntry(newEntry); FileStream input = File.OpenRead(fileList[zipFilename]); copyData(input, outputFile); input.Close(); } foreach (Profile prof in profileList) { ZipEntry newEntry = new ZipEntry(ProfileManager.ProfilePath(prof, "").TrimStart(new char[] { '\\' })); outputFile.PutNextEntry(newEntry); XmlSerializer outputter = new XmlSerializer(prof.GetType()); outputter.Serialize(outputFile, prof); } outputFile.Close(); MessageBox.Show("Completed successfully", "Export completed successfully", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } #endif }
private void okButton_Click(object sender, EventArgs e) { if (importMode) { IList list_selectedProfiles = profileListBox.SelectedItems; int i = 0; string[] selectedProfiles = new string[list_selectedProfiles.Count]; foreach (object o in list_selectedProfiles) { selectedProfiles[i] = (string)o; i++; } List <string> failedProfiles; Profile[] profileList = importedProfiles.AllProfiles(selectedProfiles, out failedProfiles); Dictionary <string, string> substitutionTable = new Dictionary <string, string>(); Dictionary <string, string> fileList = importedProfiles.AllRequiredFiles(profileList, out substitutionTable); foreach (string file in fileList.Values) { if (!extraFiles.ContainsKey(file)) { failedProfiles.Add(file); } else { string filename = Path.GetFileName(file); string pathname = mainForm.MeGUIPath + "\\extra\\" + filename; int count = 0; while (File.Exists(pathname)) { count++; pathname = mainForm.MeGUIPath + "\\extra\\" + count + "_" + filename; } if (substitutionTable.ContainsKey(file)) { substitutionTable.Remove(file); } substitutionTable.Add(file, pathname); try { if (!Directory.Exists(mainForm.MeGUIPath + "\\extra")) { Directory.CreateDirectory(mainForm.MeGUIPath + "\\extra"); } Stream outputStream = File.OpenWrite(pathname); copyData(inputFile.GetInputStream(extraFiles[file]), outputStream); outputStream.Close(); } catch (IOException ioe) { MessageBox.Show( string.Format("Error opening selected file: {0}{1}{0}Import cancelled", Environment.NewLine, ioe.Message), "Error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } } } ProfileManager.FixFileNames(profileList, substitutionTable); profiles.AddAll(profileList, mainForm.DialogManager); this.Close(); } else // export mode { SaveFileDialog outputFilesChooser = new SaveFileDialog(); outputFilesChooser.Title = "Choose your output file"; outputFilesChooser.Filter = "Zip archives|*.zip"; if (outputFilesChooser.ShowDialog() != DialogResult.OK) { return; } string filename = outputFilesChooser.FileName; IList list_selectedProfiles = profileListBox.SelectedItems; int i = 0; string[] selectedProfiles = new string[list_selectedProfiles.Count]; foreach (object o in list_selectedProfiles) { selectedProfiles[i] = (string)o; i++; } List <string> failedProfiles; Profile[] profileList = profiles.AllProfiles(selectedProfiles, out failedProfiles); Dictionary <string, string> substitutionTable = new Dictionary <string, string>(); Dictionary <string, string> fileList = profiles.AllRequiredFiles(profileList, out substitutionTable); ProfileManager.FixFileNames(profileList, substitutionTable); ZipOutputStream outputFile = new ZipOutputStream(File.OpenWrite(filename)); foreach (string zipFilename in fileList.Keys) { ZipEntry newEntry = new ZipEntry(zipFilename); outputFile.PutNextEntry(newEntry); FileStream input = File.OpenRead(fileList[zipFilename]); copyData(input, outputFile); input.Close(); } foreach (Profile prof in profileList) { ZipEntry newEntry = new ZipEntry(ProfileManager.ProfilePath(prof, "").TrimStart(new char[] { '\\' })); outputFile.PutNextEntry(newEntry); XmlSerializer outputter = new XmlSerializer(prof.GetType()); outputter.Serialize(outputFile, prof); } outputFile.Close(); MessageBox.Show("Completed successfully", "Export completed successfully", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } }
public ProfilePorter(ProfileManager profiles, MainForm mainForm, byte[] data) : this(profiles, true, mainForm) { inputFile = new ZipFile(new MemoryStream(data)); }
private void ProfileExporter_Load(object sender, EventArgs e) { if (!importMode) { profileListBox.DataSource = profiles.AllProfileNames; return; } extraFiles = new Dictionary <string, ZipEntry>(); if (inputFile == null) { if (inputFileName == null || inputFileName.Length == 0) { OpenFileDialog inputChooser = new OpenFileDialog(); inputChooser.Filter = "Zip archives|*.zip"; inputChooser.Title = "Select your input file"; if (inputChooser.ShowDialog() != DialogResult.OK) { Close(); return; } inputFileName = inputChooser.FileName; } try { inputFile = new ZipFile(File.OpenRead(inputFileName)); } catch (IOException ioe) { MessageBox.Show( string.Format("Error opening selected file: {0}{1}{0}Import cancelled", Environment.NewLine, ioe.Message), "Error opening file", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); return; } } importedProfiles = new ProfileManager(""); XmlSerializer videoSerializer, audioSerializer, avsSerializer, oneclickSerializer; videoSerializer = new XmlSerializer(typeof(GenericProfile <VideoCodecSettings>)); audioSerializer = new XmlSerializer(typeof(GenericProfile <AudioCodecSettings>)); avsSerializer = new XmlSerializer(typeof(GenericProfile <AviSynthSettings>)); oneclickSerializer = new XmlSerializer(typeof(GenericProfile <OneClickSettings>)); #warning We are generating a list of failed attempts, but we aren't doing anything with it (below). List <string> failedEntries = new List <string>(); foreach (ZipEntry entry in inputFile) { // Check if the entry is in the video/audio/avs/oneclick/extra folders. // Try to deserialize if it is a profile, list the files in the extra folders #region terribly boring cases if (entry.IsFile) { if (entry.Name.ToLower().StartsWith("profiles\\video") || entry.Name.ToLower().StartsWith("profiles/video")) { try { importedProfiles.AddVideoProfile( (GenericProfile <VideoCodecSettings>)videoSerializer.Deserialize(inputFile.GetInputStream(entry))); } catch (Exception) { failedEntries.Add(entry.Name); } } else if (entry.Name.ToLower().StartsWith("profiles\\audio") || entry.Name.ToLower().StartsWith("profiles/audio")) { try { importedProfiles.AddProfile( (GenericProfile <AudioCodecSettings>)audioSerializer.Deserialize(inputFile.GetInputStream(entry))); } catch (Exception) { failedEntries.Add(entry.Name); } } else if (entry.Name.ToLower().StartsWith("profiles\\avs") || entry.Name.ToLower().StartsWith("profiles/avs")) { try { importedProfiles.AddProfile( (GenericProfile <AviSynthSettings>)avsSerializer.Deserialize(inputFile.GetInputStream(entry))); } catch (Exception) { failedEntries.Add(entry.Name); } } else if (entry.Name.ToLower().StartsWith("profiles\\oneclick") || entry.Name.ToLower().StartsWith("profiles/oneclick")) { try { importedProfiles.AddProfile( (GenericProfile <OneClickSettings>)oneclickSerializer.Deserialize(inputFile.GetInputStream(entry))); } catch (Exception) { failedEntries.Add(entry.Name); } } else if (entry.Name.ToLower().StartsWith("extra\\") || entry.Name.ToLower().StartsWith("extra/")) { extraFiles.Add(entry.Name, entry); } } #endregion } profileListBox.DataSource = importedProfiles.AllProfileNames; }