Skip to content

Commit 516db17

Browse files
committed
Fix the upgrade of the configuration file with available legacy file
1 parent d0bc1ea commit 516db17

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

PatternFileMover/Form1.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,20 @@ public Form1()
3030
// ensure the existance of the necessary config file
3131
if (!File.Exists(NameAssociations.configManifestPath))
3232
{
33-
// file not found
34-
// typically at the first usage of the program
35-
// create an empty config file
36-
NameAssociations.CreateEmptyConfigFile();
33+
// the manifest file hasn't been found…
34+
if (File.Exists(NameAssociations.legacyConfigPath))
35+
{
36+
// … but there is a legacy config file
37+
// that means that we need to convert a `v1` config file
38+
NameAssociations.checkAndUpgradeConfigurationFile(true);
39+
}
40+
else
41+
{
42+
// file not found
43+
// typically at the first usage of the program
44+
// create an empty config file
45+
NameAssociations.CreateEmptyConfigFile();
46+
}
3747
}
3848
else
3949
{

PatternFileMover/NameAssociations.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ public static string GetConfigFilePath()
3737
".json";
3838
}
3939

40-
public static void checkAndUpgradeConfigurationFile() {
40+
public static void checkAndUpgradeConfigurationFile(bool isV1 = false) {
41+
if (isV1 == true)
42+
{
43+
File.WriteAllText(configManifestPath, "v1");
44+
}
45+
4146
string manifestVersion = File.ReadAllText(Path.GetFullPath(configManifestPath));
4247

4348
if (!File.Exists(Path.GetFullPath(GetConfigFilePath())))
@@ -62,6 +67,7 @@ public static void checkAndUpgradeConfigurationFile() {
6267
});
6368
}
6469

70+
File.WriteAllText(configManifestPath, "v2");
6571
WriteByList(convertedValues);
6672
}
6773
}

0 commit comments

Comments
 (0)