/// <summary> /// Saves the content. /// </summary> /// <param name="storage">The storage.</param> /// <returns></returns> /// <remarks>Documented by Dev02, 2008-10-09</remarks> public static string SerializeData(VolumeDataStorage storage) { if (xmlSerializer == null) { xmlSerializer = new XmlSerializer(typeof(VolumeDataStorage)); } StringWriter writer = new StringWriter(); xmlSerializer.Serialize(writer, storage); return(writer.ToString()); }
/// <summary> /// Handles the click events of the buttonStartChecking and buttonStartCopy controls. /// </summary> /// <param name="checking">if set to <c>true</c> [checking].</param> /// <remarks>Documented by Dev02, 2008-10-09</remarks> private void StartProcess(bool checking) { CheckSticks = checking; Properties.Settings.Default.InputPath = textBoxInputFilePath.Text; Properties.Settings.Default.Save(); if (!processStarted) //Start the Stick Detection and Copy Process { groupBoxInput.Enabled = false; ZipFile zipFile = new ZipFile(textBoxInputFilePath.Text); VolumeDataStorage vds = VolumeDataStorage.DeserializeData(zipFile.ZipFileComment); zipFile.Close(); if (checking) { buttonStartChecking.Text = "Stop checking engine"; } else { buttonStartCopy.Text = "Stop copy engine"; } processStarted = true; (checking ? buttonStartCopy : buttonStartChecking).Enabled = false; if (loadingThreadFinished != MainForm_mainThreadLoadingFinished) { loadingThreadFinished += new EventHandler(MainForm_mainThreadLoadingFinished); } loadingThread = new Thread(LoadingProcessThread); loadingThread.IsBackground = true; loadingThread.Name = "Loading Thread"; loadingThread.Start(); usbStickWriter.StickName = vds.VolumeLabel; usbStickWriter.StickID = vds.VolumeSerial; usbStickWriter.CopyContent = !checking; usbStickWriter.CheckContent = checking; usbStickWriter.FileAttributes.Clear(); foreach (KeyValuePair <string, FileAttributes> pair in vds.FileAttributeList) { usbStickWriter.FileAttributes.Add(pair.Key, pair.Value); } foreach (KeyValuePair <string, FileAttributes> pair in vds.FolderAttributeList) { usbStickWriter.FolderAttributes.Add(pair.Key, pair.Value); } } else //Stop the Stick Detection and Copy Process { groupBoxInput.Enabled = true; if (checking) { buttonStartChecking.Text = "Start checking engine"; } else { buttonStartCopy.Text = "Start copy engine"; } processStarted = false; loadingSuccessful = false; (checking ? buttonStartCopy : buttonStartChecking).Enabled = true; usbStickWriter.AbortWriting(); if (loadingThread.IsAlive) { loadingThread.Abort(); SetStatusMessage("Process canceled by user"); } } }
/// <summary> /// Generates the image. /// </summary> /// <remarks>CFI, 2012-02-24</remarks> private void GenerateImage() { #region Check parameter: if (!Directory.Exists(textBoxInputFilePath.Text)) { throw new DirectoryNotFoundException("The input directory was not found!"); } if (!Directory.Exists(Path.GetDirectoryName(textBoxOutputFile.Text))) { throw new DirectoryNotFoundException("The output path is invalid!"); } if (textBoxStickName.Text.Length > 11 || textBoxStickName.Text == string.Empty) { throw new ArgumentException("Invalid Stick name!"); } if (textBoxStickID.Text.Length != 9 || textBoxStickID.Text[4] != '-') { throw new ArgumentException("Invalid Stick ID!"); } #endregion string outputFilePath = Path.ChangeExtension(textBoxOutputFile.Text, ".MLifterStick"); #region Create Zip: Stream output = File.Create(outputFilePath); ZipOutputStream zipStream = new ZipOutputStream(output); ZipFile zip = new ZipFile(output); #endregion #region Fill Zip: zip.BeginUpdate(); int pos = 1; string[] files = Directory.GetFiles(textBoxInputFilePath.Text, "*.*", SearchOption.AllDirectories); List <string> folders = new List <string>(); foreach (string file in files) { toolStripStatusLabelMessage.Text = string.Format("Adding file {0} of {1}...", pos, files.Length); toolStripProgressBarStatus.Value = Convert.ToInt32(pos++ *1.0 / files.Length * 100); Application.DoEvents(); string dir = Path.GetDirectoryName(file).Remove(0, textBoxInputFilePath.Text.Length); string zipFile = Path.Combine(dir, Path.GetFileName(file)); if (dir.Length > 0) { if (!folders.Contains(dir)) { zip.AddDirectory(dir); folders.Add(dir); } } zip.Add(new FileDataSource(file), zipFile); } toolStripStatusLabelMessage.Text = "Saving image. THIS COULD RUN VERY LONG - PLEASE WAIT!"; Application.DoEvents(); zip.CommitUpdate(); #endregion VolumeDataStorage vds = new VolumeDataStorage(); #region setting file attributes: foreach (string file in files) { string dir = Path.GetDirectoryName(file).Remove(0, textBoxInputFilePath.Text.Length); if (dir.StartsWith("\\")) { dir = dir.Remove(0, 1); } string zipFile = Path.Combine(dir, Path.GetFileName(file)).Replace(@"\", "/"); ZipEntry entry = zip.GetEntry(zipFile); if (entry == null) { continue; } FileAttributes attr = (new FileInfo(file)).Attributes; if (!(attr == FileAttributes.Archive || attr == FileAttributes.Normal)) { vds.FileAttributeList.Add(entry.Name, attr); } toolStripStatusLabelMessage.Text = "Setting file FileAttributes to: " + zipFile; } foreach (string folder in folders) { FileAttributes attr = (new DirectoryInfo(Path.Combine(textBoxInputFilePath.Text, folder))).Attributes; if (!(attr == FileAttributes.Archive || attr == FileAttributes.Normal || attr == FileAttributes.Directory)) { vds.FolderAttributeList.Add(folder, attr); } toolStripStatusLabelMessage.Text = "Setting folder FileAttributes to: " + folder; } #endregion #region Set Comment: vds.VolumeLabel = textBoxStickName.Text; vds.VolumeSerial = textBoxStickID.Text; string comment = VolumeDataStorage.SerializeData(vds); File.WriteAllText(Path.Combine(Application.StartupPath, "Comment.txt"), comment); zip.BeginUpdate(); zip.SetComment(comment); zip.CommitUpdate(); #endregion zip.Close(); CreatedImage = outputFilePath; }
/// <summary> /// Saves the content. /// </summary> /// <param name="storage">The storage.</param> /// <returns></returns> /// <remarks>Documented by Dev02, 2008-10-09</remarks> public static string SerializeData(VolumeDataStorage storage) { if (xmlSerializer == null) xmlSerializer = new XmlSerializer(typeof(VolumeDataStorage)); StringWriter writer = new StringWriter(); xmlSerializer.Serialize(writer, storage); return writer.ToString(); }
/// <summary> /// Generates the image. /// </summary> /// <remarks>CFI, 2012-02-24</remarks> private void GenerateImage() { #region Check parameter: if (!Directory.Exists(textBoxInputFilePath.Text)) throw new DirectoryNotFoundException("The input directory was not found!"); if (!Directory.Exists(Path.GetDirectoryName(textBoxOutputFile.Text))) throw new DirectoryNotFoundException("The output path is invalid!"); if (textBoxStickName.Text.Length > 11 || textBoxStickName.Text == string.Empty) throw new ArgumentException("Invalid Stick name!"); if (textBoxStickID.Text.Length != 9 || textBoxStickID.Text[4] != '-') throw new ArgumentException("Invalid Stick ID!"); #endregion string outputFilePath = Path.ChangeExtension(textBoxOutputFile.Text, ".MLifterStick"); #region Create Zip: Stream output = File.Create(outputFilePath); ZipOutputStream zipStream = new ZipOutputStream(output); ZipFile zip = new ZipFile(output); #endregion #region Fill Zip: zip.BeginUpdate(); int pos = 1; string[] files = Directory.GetFiles(textBoxInputFilePath.Text, "*.*", SearchOption.AllDirectories); List<string> folders = new List<string>(); foreach (string file in files) { toolStripStatusLabelMessage.Text = string.Format("Adding file {0} of {1}...", pos, files.Length); toolStripProgressBarStatus.Value = Convert.ToInt32(pos++ * 1.0 / files.Length * 100); Application.DoEvents(); string dir = Path.GetDirectoryName(file).Remove(0, textBoxInputFilePath.Text.Length); string zipFile = Path.Combine(dir, Path.GetFileName(file)); if (dir.Length > 0) { if (!folders.Contains(dir)) { zip.AddDirectory(dir); folders.Add(dir); } } zip.Add(new FileDataSource(file), zipFile); } toolStripStatusLabelMessage.Text = "Saving image. THIS COULD RUN VERY LONG - PLEASE WAIT!"; Application.DoEvents(); zip.CommitUpdate(); #endregion VolumeDataStorage vds = new VolumeDataStorage(); #region setting file attributes: foreach (string file in files) { string dir = Path.GetDirectoryName(file).Remove(0, textBoxInputFilePath.Text.Length); if (dir.StartsWith("\\")) dir = dir.Remove(0, 1); string zipFile = Path.Combine(dir, Path.GetFileName(file)).Replace(@"\", "/"); ZipEntry entry = zip.GetEntry(zipFile); if (entry == null) continue; FileAttributes attr = (new FileInfo(file)).Attributes; if (!(attr == FileAttributes.Archive || attr == FileAttributes.Normal)) vds.FileAttributeList.Add(entry.Name, attr); toolStripStatusLabelMessage.Text = "Setting file FileAttributes to: " + zipFile; } foreach (string folder in folders) { FileAttributes attr = (new DirectoryInfo(Path.Combine(textBoxInputFilePath.Text, folder))).Attributes; if (!(attr == FileAttributes.Archive || attr == FileAttributes.Normal || attr == FileAttributes.Directory)) vds.FolderAttributeList.Add(folder, attr); toolStripStatusLabelMessage.Text = "Setting folder FileAttributes to: " + folder; } #endregion #region Set Comment: vds.VolumeLabel = textBoxStickName.Text; vds.VolumeSerial = textBoxStickID.Text; string comment = VolumeDataStorage.SerializeData(vds); File.WriteAllText(Path.Combine(Application.StartupPath, "Comment.txt"), comment); zip.BeginUpdate(); zip.SetComment(comment); zip.CommitUpdate(); #endregion zip.Close(); CreatedImage = outputFilePath; }