private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            for (int i = 0; i < files.Count; i++)
            {
                currentFile = files[i];
                currentPath = targetPath + System.IO.Path.DirectorySeparatorChar + FIB.ProcessPath(currentFile.Path);
                string target_dir = System.IO.Path.GetDirectoryName(currentPath);

                try
                {
                    if (!System.IO.Directory.Exists(target_dir))
                    {
                        System.IO.Directory.CreateDirectory(target_dir);
                    }
                    currentFile.Extract(currentPath);
                    filesCompleted++;
                }
                catch (Exception ex)
                {
                    DialogResult result = MessageBox.Show(String.Format("Cannot extract file '{0}': {1}", currentFile.Filename, ex.Message), "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
                    if (result == System.Windows.Forms.DialogResult.Cancel)
                    {
                        this.DialogResult = DialogResult.Cancel;
                        return;
                    }
                    else
                    {
                        i--;
                    }
                }
            }

            this.DialogResult = DialogResult.OK;
        }
Esempio n. 2
0
        private void ExtractAndOpen(string filePath)
        {
            // Find the file.
            RCH2File file = FindFileByPath(filePath);

            if (file == null)
            {
                MessageBox.Show("Cannot find specified path in the internal lists.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Extract to temporary folder.
            string targetPath = FIB.GetTemporaryPath(System.IO.Path.GetFileName(FIB.ProcessPath(file.Filename)));

            try
            {
                file.Extract(targetPath);
                System.Diagnostics.Process proc = new System.Diagnostics.Process();
                proc.StartInfo.FileName = targetPath;
                proc.Start();
                FIB.DelSchedule(targetPath);
            }
            catch (Exception e)
            {
                MessageBox.Show("Cannot extract file: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker bw            = sender as BackgroundWorker;
            bool             showIdentical = cbShowIdentical.Checked;
            bool             showDifferent = cbDifferent.Checked;
            bool             showUnique    = cbUnique.Checked;
            string           targetPath    = (string)e.Argument;

            extractCurrentFile = 0;
            extractTotalFiles  =
                (showIdentical ? CompareInstance.IdenticalFiles.Count : 0) +
                (showDifferent ? CompareInstance.File1.DifferentFiles.Count + CompareInstance.File2.DifferentFiles.Count : 0) +
                (showUnique ? CompareInstance.File1.UniqueFiles.Count + CompareInstance.File2.UniqueFiles.Count : 0);

            // Create File1 and File2 folders.
            string file1path = targetPath + Path.DirectorySeparatorChar + FileName1;
            string file2path = targetPath + Path.DirectorySeparatorChar + FileName2;

            Directory.CreateDirectory(file1path);
            Directory.CreateDirectory(file2path);

            // Extract the files mentioned.
            if (showIdentical)
            {
                foreach (RCH2File file in CompareInstance.IdenticalFiles)
                {
                    string processedPath = FIB.ProcessPath(file.Path);
                    string file1full     = file1path + Path.DirectorySeparatorChar + processedPath;
                    string file2full     = file2path + Path.DirectorySeparatorChar + processedPath;
                    Directory.CreateDirectory(Path.GetDirectoryName(file1full));
                    Directory.CreateDirectory(Path.GetDirectoryName(file2full));

                    file.Extract(file1full);
                    File.Copy(file1full, file2full, true);
                    extractCurrentFile++;

                    if (bw.CancellationPending)
                    {
                        goto bgwCancel;
                    }
                }
            }

            if (showDifferent)
            {
                foreach (RCH2File file in CompareInstance.File1.DifferentFiles)
                {
                    RCH2File file2         = FIB.FindFileByPath(CompareInstance.File2.Container, file.Path);
                    string   processedPath = FIB.ProcessPath(file.Path);
                    string   file1full     = file1path + Path.DirectorySeparatorChar + processedPath;
                    string   file2full     = file2path + Path.DirectorySeparatorChar + processedPath;
                    Directory.CreateDirectory(Path.GetDirectoryName(file1full));
                    Directory.CreateDirectory(Path.GetDirectoryName(file2full));

                    file.Extract(file1full);
                    file2.Extract(file2full);
                    extractCurrentFile += 2;

                    if (bw.CancellationPending)
                    {
                        goto bgwCancel;
                    }
                }
            }

            if (showUnique)
            {
                bool flag = true;
                foreach (List <RCH2File> list in new List <RCH2File>[] { CompareInstance.File1.UniqueFiles, CompareInstance.File2.UniqueFiles })
                {
                    foreach (RCH2File file in list)
                    {
                        string full = (flag ? file1path : file2path) + Path.DirectorySeparatorChar + FIB.ProcessPath(file.Path);
                        Directory.CreateDirectory(Path.GetDirectoryName(full));
                        file.Extract(full);
                        extractCurrentFile++;

                        if (bw.CancellationPending)
                        {
                            goto bgwCancel;
                        }
                    }
                    flag = false;
                }
            }

            return;

bgwCancel:
            e.Cancel = true;
        }