Ejemplo n.º 1
0
        /// <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");
                }
            }
        }