-
Notifications
You must be signed in to change notification settings - Fork 3
/
QuickSaveDialog.cs
85 lines (71 loc) · 2.27 KB
/
QuickSaveDialog.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace JarrettVance.ChapterTools
{
public partial class QuickSaveDialog : Form
{
private readonly ChapterInfo pgc;
public QuickSaveDialog(ChapterInfo pgc)
{
InitializeComponent();
this.pgc = pgc;
QuickSave(Settings.Default.LastOpenDir);
}
private void QuickSave(string path)
{
lblStatus.Text = string.Empty;
txtFolder.Text = path;
if (String.IsNullOrEmpty(path))
{
lblStatus.Text = "Please choose a destination folder.";
btnDir.Focus();
return;
}
if (this.pgc.Chapters.Count == 0)
{
lblStatus.Text = "No chapters to save.";
btnOK.Focus();
return;
}
try
{
string name = (pgc.Title ?? pgc.SourceName ?? "Chapters");
name = Pathing.FileNameUtils.MakeValidFileName(name);
path = Path.Combine(path, name);
lblStatus.Text += "Saving to '" + path + ".chapters" + "'" + Environment.NewLine;
pgc.Save(path + ".chapters");
lblStatus.Text += "Saving to '" + path + ".xml" + "'" + Environment.NewLine;
pgc.SaveXml(path + ".xml");
lblStatus.Text += "Saving to '" + path + ".chapters.txt" + "'" + Environment.NewLine;
pgc.SaveText(path + ".chapters.txt");
lblStatus.Text += "Done.";
}
catch (UnauthorizedAccessException)
{
lblStatus.Text = "The folder is read-only. Please choose a different folder.";
btnDir.Focus();
}
catch (Exception ex)
{
lblStatus.Text += ex.Message;
}
}
private void btnDir_Click(object sender, EventArgs e)
{
using (FolderBrowserDialog d = new FolderBrowserDialog())
{
d.Description = "Select a folder.";
if (d.ShowDialog() == DialogResult.OK)
{
QuickSave(d.SelectedPath);
}
}
}
}
}