Skip to content

Commit 2fb8ed9

Browse files
committed
add Config
1 parent b635d81 commit 2fb8ed9

4 files changed

Lines changed: 2771 additions & 2563 deletions

File tree

LazerFilesViewer/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
</configuration>

LazerFilesViewer/MainForm.Designer.cs

Lines changed: 73 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LazerFilesViewer/MainForm.cs

Lines changed: 144 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Security.Policy;
1010
using System.Windows.Forms;
1111
using System.Xml.Linq;
12+
using System.Configuration;
1213

1314
namespace LazerFilesViewer
1415
{
@@ -31,6 +32,9 @@ public partial class MainForm : Form
3132

3233
HistoryControl historyControl = new HistoryControl();
3334

35+
string DeleteWarning = "1";
36+
string CleanTemp = "1";
37+
3438
private RealmConfiguration GetConfiguration()
3539
{
3640
return new RealmConfiguration(DataBasePath)
@@ -77,6 +81,32 @@ private void BuildDirectories()
7781
}
7882
}
7983
r.Dispose();
84+
AddUpdateAppSettings("LazerPath", LazerPath);
85+
AddUpdateAppSettings("LazerFilePath", LazerFilePath);
86+
AddUpdateAppSettings("DataBasePath", DataBasePath);
87+
}
88+
89+
static void AddUpdateAppSettings(string key, string value)
90+
{
91+
try
92+
{
93+
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
94+
var settings = configFile.AppSettings.Settings;
95+
if (settings[key] == null)
96+
{
97+
settings.Add(key, value);
98+
}
99+
else
100+
{
101+
settings[key].Value = value;
102+
}
103+
configFile.Save(ConfigurationSaveMode.Modified);
104+
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
105+
}
106+
catch (ConfigurationErrorsException)
107+
{
108+
Console.WriteLine("Error writing app settings");
109+
}
80110
}
81111

82112
private enum FileListIcons
@@ -204,8 +234,48 @@ public MainForm()
204234
InitializeComponent();
205235
}
206236

237+
238+
static void DeleteFolder(string path)
239+
{
240+
foreach (string file in Directory.GetFiles(path))
241+
{
242+
File.Delete(file);
243+
}
244+
245+
foreach (string dir in Directory.GetDirectories(path))
246+
{
247+
DeleteFolder(dir);
248+
}
249+
250+
Directory.Delete(path);
251+
}
252+
207253
private void MainForm_Load(object sender, EventArgs e)
208254
{
255+
DeleteWarning = ConfigurationManager.AppSettings["DeleteWarning"] ?? DeleteWarning;
256+
DeleteWarningStripMenuItem.Checked = (DeleteWarning == "1") ? true : false;
257+
CleanTemp = ConfigurationManager.AppSettings["CleanTemp"] ?? CleanTemp;
258+
CleanTempStripMenuItem.Checked = (CleanTemp == "1") ? true : false;
259+
if (CleanTemp == "1")
260+
{
261+
try
262+
{
263+
if (Directory.Exists(TempFolder))
264+
{
265+
DeleteFolder(TempFolder);
266+
}
267+
}
268+
catch (Exception ex)
269+
{
270+
MessageBox.Show("清空临时文件夹失败。\r\n" + ex, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
271+
}
272+
}
273+
274+
275+
276+
DataBasePath = ConfigurationManager.AppSettings["DataBasePath"] ?? DataBasePath;
277+
LazerPath = ConfigurationManager.AppSettings["LazerPath"] ?? LazerPath;
278+
LazerFilePath = ConfigurationManager.AppSettings["LazerFilePath"] ?? LazerFilePath;
209279
if (!File.Exists(DataBasePath))
210280
{
211281
OpenFileDialog openFileDialog = new OpenFileDialog();
@@ -628,21 +698,33 @@ private void TSMI_File_OpenFolder_Click(object sender, EventArgs e)
628698
}
629699
}
630700

701+
private void DeleteSelected()
702+
{
703+
foreach (FakeFile ff in SelectedItemsList.FakeFiles)
704+
{
705+
string sourcePath = LazerFilePath + ff.GetFilePath();
706+
FileSystem.DeleteFile(sourcePath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
707+
}
708+
Reload();
709+
Process p = new Process();
710+
p.StartInfo.FileName = "explorer.exe";
711+
p.StartInfo.Arguments = "shell:RecycleBinFolder";
712+
p.Start();
713+
}
714+
631715
private void TSMI_File_EnableMulti_Delete_Click(object sender, EventArgs e)
632716
{
633-
DialogResult result = MessageBox.Show("删除存储文件可能会造成数据库损坏或Lazer程序异常,请小心使用!\r\n该操作会影响到所有使用该文件的谱面、皮肤等!", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
634-
if (result == DialogResult.OK)
717+
if (DeleteWarning == "1")
635718
{
636-
foreach (FakeFile ff in SelectedItemsList.FakeFiles)
719+
DialogResult result = MessageBox.Show("删除存储文件可能会造成数据库损坏或Lazer程序异常,请小心使用!\r\n该操作会影响到所有使用该文件的谱面、皮肤等!", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
720+
if (result == DialogResult.OK)
637721
{
638-
string sourcePath = LazerFilePath + ff.GetFilePath();
639-
FileSystem.DeleteFile(sourcePath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
722+
DeleteSelected();
640723
}
641-
Reload();
642-
Process p = new Process();
643-
p.StartInfo.FileName = "explorer.exe";
644-
p.StartInfo.Arguments = "shell:RecycleBinFolder";
645-
p.Start();
724+
}
725+
else
726+
{
727+
DeleteSelected();
646728
}
647729
}
648730

@@ -845,7 +927,7 @@ private void TSMI_File_GoToFolder_Click(object sender, EventArgs e)
845927
string folderPath = fullName.Substring(0, index);
846928
string fileName = fullName.Substring(index + 1);
847929
OpenPath(folderPath);
848-
foreach(ListViewItem item in FileListView.Items)
930+
foreach (ListViewItem item in FileListView.Items)
849931
{
850932
if (item.SubItems[0].Text == fileName)
851933
{
@@ -860,6 +942,56 @@ private void TSMI_File_GoToFolder_Click(object sender, EventArgs e)
860942
OpenPath("");
861943
}
862944
}
945+
946+
private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
947+
{
948+
Close();
949+
}
950+
951+
private void SetDatabasePathToolStripMenuItem_Click(object sender, EventArgs e)
952+
{
953+
OpenFileDialog openFileDialog = new OpenFileDialog();
954+
openFileDialog.Filter = "Realm数据库 (*.realm)|*.realm";
955+
openFileDialog.Title = "选择Lazer数据库文件";
956+
openFileDialog.Multiselect = false;
957+
openFileDialog.CheckFileExists = true;
958+
openFileDialog.CheckPathExists = true;
959+
if (openFileDialog.ShowDialog() == DialogResult.OK)
960+
{
961+
DataBasePath = openFileDialog.FileName;
962+
LazerPath = DataBasePath.Substring(0, DataBasePath.LastIndexOf("\\" + 1));
963+
LazerFilePath = LazerPath + @"files\";
964+
}
965+
966+
try
967+
{
968+
BuildDirectories();
969+
}
970+
catch (Exception ex)
971+
{
972+
DialogResult result = MessageBox.Show("读取数据库错误!\r\n" + ex, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
973+
if (result == DialogResult.OK)
974+
{
975+
Close();
976+
}
977+
}
978+
979+
OpenPath("");
980+
}
981+
982+
private void DeleteWarningStripMenuItem_Click(object sender, EventArgs e)
983+
{
984+
if (DeleteWarning == "1") DeleteWarning = "-1";
985+
else DeleteWarning = "1";
986+
AddUpdateAppSettings("DeleteWarning", DeleteWarning);
987+
}
988+
989+
private void CleanTempStripMenuItem_Click(object sender, EventArgs e)
990+
{
991+
if (CleanTemp == "1") CleanTemp = "-1";
992+
else CleanTemp = "1";
993+
AddUpdateAppSettings("CleanTemp", CleanTemp);
994+
}
863995
}
864996

865997
public class SelectedItemsList
@@ -981,4 +1113,5 @@ public bool HasFront()
9811113
return (CurrentIndex < HistoryPoints.Count - 1);
9821114
}
9831115
}
1116+
9841117
}

0 commit comments

Comments
 (0)