-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.cs
49 lines (45 loc) · 1.25 KB
/
Helper.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
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ACCServerManager
{
class Helper
{
public static string presetPath = AppDomain.CurrentDomain.BaseDirectory + @"Presets\";
/// <summary>
/// Copies the contents of event.json to startup.json
/// </summary>
public static void InitializeStartupJson(string eventFilePath)
{
string eventJsonData = File.ReadAllText(eventFilePath);
File.WriteAllText(presetPath + "startup.json", eventJsonData);
}
public static bool SaveToPreset(Event eventObjectToSave)
{
string fileName = GetSaveFileDialogFileName();
if (fileName == null)
{
return false;
}
File.WriteAllText(fileName, JsonConvert.SerializeObject(eventObjectToSave, Formatting.Indented));
return true;
}
private static string GetSaveFileDialogFileName()
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "JSON file|*.json";
saveFileDialog1.Title = "Save a preset";
saveFileDialog1.InitialDirectory = presetPath;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
return saveFileDialog1.FileName;
}
return null;
}
}
}