Что то никак не получается, каждый файл сохранить в отдельном архиве.. он сразу все в один архив сует.. кто знает как вылечить? Если это конечно возможно, как я понел либа такова не умеет...  Вышло пока что только так:
Код |
private void button2_Click(object sender, EventArgs e) { listBox1.Items.Clear(); allfiles = Directory.GetFileSystemEntries(gamePath.Text, "*.*", SearchOption.AllDirectories); progressBar1.Minimum = 0; progressBar1.Maximum = allfiles.Length; progressBar1.Value = 0; progressBar1.Step = 1;
if (WORKER.IsBusy != true) WORKER.RunWorkerAsync(); }
private void WORKER_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; if (worker.CancellationPending == true) { e.Cancel = true; } else { String path = gamePath.Text;
if (Directory.Exists(path)) { for (int i = 0; i < allfiles.Length; i++) { WORKER.ReportProgress(i); addText(allfiles[i].Replace(gamePath.Text, "")); } } else MessageBox.Show("No Have Dir: " + path); } } private void WORKER_ProgressChanged(object sender, ProgressChangedEventArgs e) { //MessageBox.Show("percent: " + Convert.ToString(e.ProgressPercentage)); Instance.progressBar1.Value = e.ProgressPercentage; } private void WORKER_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { MessageBox.Show("Файлов, для архивирования: " + allfiles.Length); goZip(Environment.CurrentDirectory + @"\packed\", allfiles); } private void addText(string newText) { if (Instance.listBox1.InvokeRequired) Instance.listBox1.Invoke(new Action<string>((s) => Instance.listBox1.Items.Add(s)), newText); else Instance.listBox1.Items.Add(newText); }
private SevenZipCompressor zip; delegate void SetProgressDelegate(ProgressEventArgs args); delegate void SetInfoDelegate(FileNameEventArgs args); delegate void SetNoArgsDelegate(); /// <summary> /// Архивирование списка файлов. /// </summary> /// <param name="zipPath">Папка, куда сохраняем архивы.</param> /// <param name="fileFullNames">Массив имен файлов для запаковки. Пример одной записи: "/folder/1/text/test/file1.7z")</param> private void goZip(string zipPath, string[] fileFullNames) { Instance.progressBar1.Maximum = 100;// *allfiles.Length; if (!Directory.Exists(zipPath)) Directory.CreateDirectory(zipPath);
zip = new SevenZipCompressor(); // Создаем объект для работы с архивом zip.CompressionLevel = CompressionLevel.Ultra; // Задаем максимальную степень сжатия
zip.Compressing += new EventHandler<ProgressEventArgs>(Compressing); zip.FileCompressionStarted += new EventHandler<FileNameEventArgs>(FileCompressionStarted); zip.CompressionFinished += new EventHandler<EventArgs>(CompressionFinished);
try { zip.BeginCompressFiles(zipPath + "test.7z", fileFullNames); } catch (Exception e) { MessageBox.Show("Error:\n" + e); } }
private void Compressing(object sender, ProgressEventArgs e) { this.Text = String.Format("[Complited] {0} %", e.PercentDone); Instance.progressBar1.Value = e.PercentDone; }
private void FileCompressionStarted(object sender, FileNameEventArgs e) { //this.Text = String.Format("file: {0} percent: {1} %", e.FileName, e.PercentDone); }
private void CompressionFinished(object sender, EventArgs e) { progressBar1.Value = 0; MessageBox.Show("Архивирование закончено!"); }
|
|