-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainForm.cs
154 lines (137 loc) · 5.34 KB
/
MainForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using IOFile = System.IO.File;
using System.Security.Cryptography;
using System.Threading;
namespace DeltaZip
{
public partial class MainForm : Form
{
static string Filter = "Archive|*" + Settings.ArchiveExtension;
public MainForm()
{
InitializeComponent();
if (Settings.SelectExtractTab) {
tabControl1.SelectTab(tabPage2);
extractSrc.Text = Program.GetMostRecentArchive(Settings.Src);
extractDst.Text = Settings.Dst;
if (!string.IsNullOrEmpty(Settings.Src)) {
foreach (string file in Directory.GetFiles(Path.GetDirectoryName(Settings.Src), "*" + Settings.ArchiveExtension)) {
extractSrc.Items.Add(file);
}
}
}
labelMOTD.Text = Settings.MessageOfTheDay;
}
private void createSrcSelect_Click(object sender, EventArgs e)
{
FolderBrowserDialog dirDialog = new FolderBrowserDialog();
dirDialog.SelectedPath = createSrc.Text;
if (dirDialog.ShowDialog() == DialogResult.OK) {
createSrc.Text = dirDialog.SelectedPath;
if (string.IsNullOrEmpty(createDst.Text)) {
RefreshDstDir();
}
}
}
private void createDstSelect_Click(object sender, EventArgs e)
{
if (optMulti.Checked) {
FolderBrowserDialog dirDialog = new FolderBrowserDialog();
dirDialog.SelectedPath = createDst.Text;
if (dirDialog.ShowDialog() == DialogResult.OK) {
createDst.Text = dirDialog.SelectedPath + Path.DirectorySeparatorChar;
}
} else {
SaveFileDialog saveDialog = new SaveFileDialog();
saveDialog.FileName = createDst.Text;
saveDialog.Filter = Filter;
if (saveDialog.ShowDialog() == DialogResult.OK) {
createDst.Text = saveDialog.FileName;
}
}
}
private void createRefSelect_Click(object sender, EventArgs e)
{
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.FileName = createRef.Text;
openDlg.Filter = Filter;
if (openDlg.ShowDialog() == DialogResult.OK) {
createRef.Text = openDlg.FileName;
}
}
private void optMulti_CheckedChanged(object sender, EventArgs e)
{
RefreshDstDir();
}
void RefreshDstDir()
{
if (optMulti.Checked) {
createDst.Text = createSrc.Text + Path.DirectorySeparatorChar;
} else {
createDst.Text = createSrc.Text + Settings.ArchiveExtension;
}
}
private void createBtn_Click(object sender, EventArgs e)
{
Settings.Create = true;
Settings.Src = createSrc.Text;
Settings.Dst = createDst.Text;
Settings.Ref = createRef.Text;
Settings.RefRecent = createRefAuto.Checked;
Settings.Verify = optVerify.Checked;
Settings.CreateMulti = optMulti.Checked;
if (string.IsNullOrEmpty(Settings.Src) || string.IsNullOrEmpty(Settings.Dst)) return;
this.Close();
}
void extractSrcSelect_Click(object sender, EventArgs e)
{
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.FileName = extractSrc.Text;
openDlg.Filter = Filter;
if (openDlg.ShowDialog() == DialogResult.OK) {
extractSrc.Text = openDlg.FileName;
if (string.IsNullOrEmpty(extractDst.Text)) {
extractDst.Text = Path.Combine(Path.GetDirectoryName(extractSrc.Text), Path.GetFileNameWithoutExtension(extractSrc.Text));
}
}
}
void extractDstSelect_Click(object sender, EventArgs e)
{
FolderBrowserDialog dirDialog = new FolderBrowserDialog();
dirDialog.SelectedPath = extractDst.Text;
if (dirDialog.ShowDialog() == DialogResult.OK) {
extractDst.Text = dirDialog.SelectedPath;
}
}
void extractBtn_Click(object sender, EventArgs e)
{
Settings.Extract = true;
Settings.Src = extractSrc.Text;
Settings.Dst = extractDst.Text;
this.Close();
}
void verifySrcSelect_Click(object sender, EventArgs e)
{
OpenFileDialog openDlg = new OpenFileDialog();
openDlg.Filter = Filter;
if (openDlg.ShowDialog() == DialogResult.OK) {
verifySrc.Text = openDlg.FileName;
}
}
void verifyBtn_Click(object sender, EventArgs e)
{
Settings.Verify = true;
Settings.Src = verifySrc.Text;
Settings.Dst = null;
this.Close();
}
}
}