/* ----------------------------------------------------------------- */ /// /// NewVM /// /// <summary> /// Creates a new instance of the CompressViewModel class with /// the specified arguments. /// </summary> /// /// <param name="args">Program arguments.</param> /// <param name="settings">User settings for compression.</param> /// /// <returns>CompressViewModel object.</returns> /// /* ----------------------------------------------------------------- */ protected CompressViewModel NewVM(IEnumerable <string> args, CompressSetting settings) { var ss = NewSettings(); ss.Value.Compress = settings; ss.Value.Compress.OpenMethod = OpenMethod.None; ss.Value.Compress.SaveDirectory = Get("Preset"); return(new CompressViewModel(new(args), ss, new())); }
public void Overwrite() { var dir = Get("Overwrite"); var src = new[] { GetSource("Sample.txt") }; var dest = Io.Combine(dir, "Sample.zip"); var args = Preset.Compress.ToArguments().Concat(src); var value = new CompressSetting { SaveLocation = SaveLocation.Query, OpenMethod = OpenMethod.None, }; Io.Copy(GetSource("Single.1.0.0.zip"), dest, true); using var vm = NewVM(args, value); using (vm.SetDestination(dest)) vm.Test(); Assert.That(Io.Exists(dest), Is.True, dest); }
public void CancelPassword() { var dir = Get("CancelPassword"); var src = new[] { GetSource("Sample.txt") }; var dest = Io.Combine(dir, "Sample.zip"); var args = Preset.CompressZipPassword.ToArguments().Concat(src); var value = new CompressSetting { SaveLocation = SaveLocation.Preset, SaveDirectory = dir, OpenMethod = OpenMethod.None, }; using var vm = NewVM(args, value); using (vm.SetDestination(dest)) vm.Test(); Assert.That(Io.Exists(dest), Is.False, dest); }
public void MoveFailed() { var dir = Get("MoveFailed"); var src = new[] { GetSource("Sample.txt") }; var dest = Io.Combine(dir, "Sample.zip"); var args = Preset.CompressZip.ToArguments().Concat(new[] { "/o:runtime" }).Concat(src); var value = new CompressSetting { SaveLocation = SaveLocation.Preset, SaveDirectory = dir, OpenMethod = OpenMethod.None, }; Io.Copy(GetSource("Single.1.0.0.zip"), dest, true); using var vm = NewVM(args, value); using (Io.Open(dest)) using (vm.SetDestination(dest)) { vm.Test(); } }
public string FolderCompress(CompressSetting setting) { string compFile = string.Empty; using (ZipFile zip = new ZipFile(Encoding.GetEncoding("Shift_JIS"))) { var fileName = setting.CompressTargetPath.Split('\\').Where(i => i != "\\").Last() + ".zip"; compFile = Path.Combine(setting.CompressTargetPath, fileName); if (setting.HasPassword == true) { zip.Password = setting.PasswordText; //zip.Encryption = Ionic.Zip.EncryptionAlgorithm.None; } zip.CompressionLevel = CompressionLevel.BestCompression; zip.AddDirectory(setting.CompressTargetPath); zip.Save(compFile); } setting.CompressFilePath = compFile; return(compFile); }
public void Compress(string dest, IEnumerable <string> files, IEnumerable <string> args, CompressSetting settings) { using var vm = NewVM(args.Concat(files.Select(e => GetSource(e))), settings); var filename = GetFileName(GetSource(files.First()), dest); var cvt = Get("Runtime", filename); using (vm.SetPassword("password")) using (vm.SetDestination(cvt)) using (vm.SetRuntime(cvt)) { Assert.That(vm.State, Is.EqualTo(TimerState.Stop)); Assert.That(vm.Cancelable, Is.False); Assert.That(vm.Suspended, Is.False); Assert.That(vm.Count, Is.Not.Null.And.Not.Empty); Assert.That(vm.Title, Does.StartWith("0%").And.EndsWith("CubeICE")); Assert.That(vm.Text, Does.StartWith("ファイルを圧縮する準備をしています")); vm.Test(); GetType().LogDebug(vm.Elapsed, vm.Remaining, vm.Title); } Assert.That(Io.Exists(Get(dest)), Is.True, dest); }
public void AttachedCompress(bool isManual) { try { CompressSetting setting; var indexList = new List <Attachment>(); if (isManual == false) { setting = new CompressSetting(); setting.CompressTargetPath = FileIo.CreateTempFolder(null); foreach (var attachment in mailItem.Attachments.Cast <Attachment>()) { //System.Diagnostics.Debug.WriteLine(attachment.GetTemporaryFilePath().ToString()); //添付されいてるファイルを圧縮用フォルダへコピー attachment.SaveAsFile(Path.Combine(setting.CompressTargetPath, attachment.FileName)); //圧縮対象ファイルを添付リストから除外 indexList.Add(attachment); } } else { var fileList = new List <string>(); foreach (var attachment in mailItem.Attachments.Cast <Attachment>()) { fileList.Add(attachment.FileName); } var settingForm = new AttachedCompressSetting(fileList.ToArray()); settingForm.StartPosition = FormStartPosition.CenterParent; settingForm.ShowDialog(); if (settingForm.DialogResult == DialogResult.OK) { setting = settingForm.Setting; setting.CompressTargetPath = FileIo.CreateTempFolder(setting.FileName); foreach (var attachment in mailItem.Attachments.Cast <Attachment>()) { //var attachment = item as Attachment; if (setting.Files.Contains(attachment.FileName) == false) { continue; } //添付されいてるファイルを圧縮用フォルダへコピー attachment.SaveAsFile(Path.Combine(setting.CompressTargetPath, attachment.FileName)); //圧縮対象ファイルを添付リストから除外 indexList.Add(attachment); } } else { return; } } this.CompressSettings.Add(setting); var zipPath = FileIo.FolderCompress(setting); mailItem.Attachments.Add(zipPath); indexList.ForEach(i => { i.Delete(); }); } catch (System.Exception ee) { MessageBox.Show(ee.ToString(), "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } }