private void FileSelectionBtn_Click(object sender, EventArgs e) { toolStripStatusLabel1.Text = ""; OpenFileDialog ofd = new OpenFileDialog { CheckFileExists = true, InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Title = "開くファイルを選択してください" }; if (ofd.ShowDialog() == DialogResult.OK) { var bytes = default(byte[]); using (var memstream = new MemoryStream()) { ofd.OpenFile().CopyTo(memstream); bytes = memstream.ToArray(); } var zfo = new ZipFileOperation(); if (zfo.IsPkZipCompressedData(bytes)) { this.testFilePath = Path.GetFullPath(ofd.FileName); this.FilePathLabel.Text = ofd.SafeFileName; this.ResultLabel.Visible = false; } else { toolStripStatusLabel1.Text = "ファイルはZip圧縮されたものではありません。"; } } }
private void CalcAndDisplay() { LockUi(false); if (File.Exists(testFilePath)) { try { int multiplier = (int)this.UnitSelectionBox.SelectedValue; string unit = CreateUnitSelectionItems()[multiplier]; bool thousandIsBit = this.ThousandIsBitCheck.Checked; double totalLen = new ZipFileOperation().CountLength(testFilePath, multiplier, thousandIsBit); string msg = $"このファイルの展開後のサイズは {totalLen:#0.##} {unit} です。"; var sb = new StringBuilder(msg); var t = thousandIsBit ? 1024 : 1000; var limitLen = long.Parse(this.FileLengthLimitBox.Text); var deltas = totalLen - limitLen; if (deltas > 0) { sb.Append(Environment.NewLine).Append($"{deltas:#0.##} {unit} 超過しています。"); } this.ResultLabel.Text = sb.ToString(); this.ResultLabel.Visible = true; } catch (Exception) { toolStripStatusLabel1.Text = "ファイルを読み取ることができませんでした"; this.ResultLabel.Visible = false; } } else { toolStripStatusLabel1.Text = "選択しているファイルが存在しません。"; this.ResultLabel.Visible = false; } LockUi(true); }