forked from jwallet/spy-spotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdater.cs
56 lines (52 loc) · 2.09 KB
/
Updater.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
using EspionSpotify.Properties;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace EspionSpotify
{
internal class Updater
{
internal const string UPDATER_DIRECTORY = "Updater";
internal const string UPDATER_TMP_DIRECTORY = "tmp_updater";
internal static string ProjectDirectory = AppDomain.CurrentDomain.BaseDirectory;
internal static string UpdaterExtractedTempDirectoryPath = $"{ProjectDirectory}{UPDATER_TMP_DIRECTORY}";
internal static string UpdaterExtractedContentDirectoryPath = $@"{UpdaterExtractedTempDirectoryPath}\{UPDATER_DIRECTORY}";
internal static string UpdaterDirectoryPath = $"{ProjectDirectory}{UPDATER_DIRECTORY}";
internal static void UpgradeSettings()
{
if (!Directory.Exists(UpdaterExtractedContentDirectoryPath)) return;
Settings.Default.Upgrade();
Settings.Default.Save();
UpdateDirectoryContent();
// DeleteOlderUserSettings();
}
private static void UpdateDirectoryContent()
{
try
{
Directory.Delete(UpdaterDirectoryPath, recursive: true);
Directory.Move(UpdaterExtractedContentDirectoryPath, UpdaterDirectoryPath);
Directory.Delete(UpdaterExtractedTempDirectoryPath);
}
catch { }
}
private static void DeleteOlderUserSettings()
{
var path = Path.GetFullPath(Path.Combine(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath, @"..\..\"));
var settingPaths = Directory.GetDirectories(path);
foreach (var settingPath in settingPaths)
{
DirectoryInfo info = new DirectoryInfo(settingPath);
if (info.Name != Application.ProductVersion)
{
Directory.Delete(settingPath, true);
}
}
}
}
}