Skip to content

Commit 6a47ebb

Browse files
committed
v1.4.3
Fixed unhandled error for FileReplace. File is now copied with overwrite BackupOriginalFile is now a public static method to support the above
1 parent eaee652 commit 6a47ebb

File tree

6 files changed

+35
-32
lines changed

6 files changed

+35
-32
lines changed

ERPLoader/ERPLoader.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Copyright>Copyright © 2021 Thomas Nguyen</Copyright>
1212
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
1313
<NeutralLanguage>en</NeutralLanguage>
14-
<Version>1.4.2</Version>
14+
<Version>1.4.3</Version>
1515
<PackageLicenseFile>LICENSE</PackageLicenseFile>
1616
<ApplicationIcon>ERPLoader.ico</ApplicationIcon>
1717
</PropertyGroup>

ERPLoader/Models/ErpFileModel.cs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public ErpFileModel(ModModel parent, string path, bool findReplaceOnly = false)
4545

4646
public void UnpackAndImport()
4747
{
48-
if (Initialized && BackupOriginalFile())
48+
if (Initialized && Utils.BackupOriginalFile(ErpFilePath))
4949
{
5050
Logger.Log($"[{ModModelParent.Name}] Patching {Path.GetFileName(ErpFilePath)}");
5151

@@ -198,27 +198,5 @@ public void Repack()
198198
Logger.Error($"[{ModModelParent.Name}] ERP file not unpacked.");
199199
}
200200
}
201-
202-
private bool BackupOriginalFile()
203-
{
204-
// If original file already exists, ignore
205-
// ! This is crucial to allow different mods modifying the same erp file without failing backup
206-
if (!File.Exists(ErpFilePath + Settings.Instance.BackupFileExtension))
207-
{
208-
try
209-
{
210-
File.Copy(ErpFilePath, ErpFilePath + Settings.Instance.BackupFileExtension);
211-
return true;
212-
}
213-
catch (Exception ex)
214-
{
215-
Logger.Error($"[{ModModelParent.Name}] Failed backing up file at {ErpFilePath}\nThis file will NOT be modded for your safety");
216-
Logger.FileWrite(ex.ToString(), Logger.MessageType.Error);
217-
return false;
218-
}
219-
}
220-
221-
return true;
222-
}
223201
}
224202
}

ERPLoader/Models/ModModel.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ public void Process()
6363
{
6464
string originalFile = Path.Combine(Settings.Instance.F1GameDirectory, relativePath);
6565
string moddedFile = Path.Combine(ModPath, relativePath);
66-
if (File.Exists(originalFile))
66+
if (Utils.BackupOriginalFile(originalFile))
6767
{
68-
File.Move(originalFile, originalFile + Settings.Instance.BackupFileExtension);
68+
Directory.CreateDirectory(Path.GetDirectoryName(originalFile));
69+
File.Copy(moddedFile, originalFile, true);
70+
}
71+
else
72+
{
73+
Logger.Warning($"[{Name}] Failed backing up file. This file will not be replaced/moded");
6974
}
70-
71-
Directory.CreateDirectory(Path.GetDirectoryName(originalFile));
72-
File.Copy(moddedFile, originalFile);
7375
});
7476

7577
ErpFileModels.ForEach(erpFileModel =>

ERPLoader/Utils.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using System.Text;
34
using System.Text.RegularExpressions;
45

@@ -60,5 +61,27 @@ public static bool ContainParentFolder(string path, Regex folderToFind)
6061

6162
return false;
6263
}
64+
65+
public static bool BackupOriginalFile(string path)
66+
{
67+
// If original backup file already exists, ignore
68+
// ! This is crucial to allow different mods modifying the same erp file without failing backup
69+
if (!File.Exists(path + Settings.Instance.BackupFileExtension))
70+
{
71+
try
72+
{
73+
File.Copy(path, path + Settings.Instance.BackupFileExtension);
74+
return true;
75+
}
76+
catch (Exception ex)
77+
{
78+
Logger.Error($"Failed backing up file at {path}\nThis file will NOT be modded for your safety");
79+
Logger.FileWrite(ex.ToString(), Logger.MessageType.Error);
80+
return false;
81+
}
82+
}
83+
84+
return true;
85+
}
6386
}
6487
}

EasyERPExplorer/EasyERPExplorer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<RepositoryUrl>https://github.com/ducng99/EasyERPMod</RepositoryUrl>
1212
<NeutralLanguage>en</NeutralLanguage>
1313
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
14-
<Version>1.4.2</Version>
14+
<Version>1.4.3</Version>
1515
<PackageIcon></PackageIcon>
1616
<PackageIconUrl />
1717
<ApplicationIcon>EasyERPExplorer.ico</ApplicationIcon>

Updater/EasyUpdater.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<OutputType>WinExe</OutputType>
55
<TargetFramework>net5.0-windows</TargetFramework>
66
<UseWPF>true</UseWPF>
7-
<Version>1.4.2</Version>
7+
<Version>1.4.3</Version>
88
<Authors>Maxhyt</Authors>
99
<Company>Maxhyt</Company>
1010
<Copyright>Copyright © 2021 Thomas Nguyen</Copyright>

0 commit comments

Comments
 (0)