-
Notifications
You must be signed in to change notification settings - Fork 4
/
AppSettings.cs
93 lines (85 loc) · 3.11 KB
/
AppSettings.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
/*
##########################################
# TikTok Downloader #
# Made by Jettcodey #
# © 2024 #
# DO NOT REMOVE THIS #
##########################################
*/
using System.Xml.Serialization;
namespace TikTok_Downloader
{
public class AppSettings
{
public class Settings
{
public bool DownloadVideosOnly { get; set; }
public bool DownloadImagesOnly { get; set; }
public bool EnableJsonLogs { get; set; }
public bool EnableDownloadLogs { get; set; }
public bool UseOldFileStructure { get; set; }
public string LastDownloadFolderPath { get; set; }
public bool FirstRun { get; set; }
}
private string directoryPath;
private string filePath;
public Settings CurrentSettings { get; set; }
public AppSettings()
{
directoryPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Jettcodey\\TikTok Downloader");
filePath = Path.Combine(directoryPath, "appsettings.xml");
CurrentSettings = new Settings();
}
public void SaveSettings()
{
try
{
if (!Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
}
using (var streamWriter = new StreamWriter(filePath))
{
var serializer = new XmlSerializer(typeof(Settings));
serializer.Serialize(streamWriter, CurrentSettings);
}
}
catch (Exception ex)
{
MessageBox.Show($"Error saving settings: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public void LoadSettings()
{
if (!File.Exists(filePath))
{
CurrentSettings = new Settings
{
DownloadVideosOnly = false,
DownloadImagesOnly = false,
EnableJsonLogs = false,
EnableDownloadLogs = false,
UseOldFileStructure = false,
LastDownloadFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "TiktokDownloads"),
FirstRun = false,
};
SaveSettings();
}
else
{
try
{
using (var streamReader = new StreamReader(filePath))
{
var serializer = new XmlSerializer(typeof(Settings));
CurrentSettings = (Settings)serializer.Deserialize(streamReader);
}
}
catch (Exception ex)
{
MessageBox.Show($"Error loading settings: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
}