Skip to content

Commit daf2c02

Browse files
committed
Fix FSUIPC AutoStart with only Run
1 parent 359f71e commit daf2c02

File tree

5 files changed

+46
-12
lines changed

5 files changed

+46
-12
lines changed

Installer/AppPackage.zip

0 Bytes
Binary file not shown.

Installer/Installer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<UpdateRequired>false</UpdateRequired>
2727
<MapFileExtensions>true</MapFileExtensions>
2828
<ApplicationRevision>0</ApplicationRevision>
29-
<ApplicationVersion>0.4.0.0</ApplicationVersion>
29+
<ApplicationVersion>0.4.1.0</ApplicationVersion>
3030
<UseApplicationTrust>false</UseApplicationTrust>
3131
<PublishWizardCompleted>true</PublishWizardCompleted>
3232
<BootstrapperEnabled>true</BootstrapperEnabled>

Installer/InstallerFunctions.cs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,22 +58,56 @@ public static bool AutoStartFsuipc()
5858
}
5959
else
6060
{
61-
string pattern = @"^RunIf(\d+).*WorkingTitle2GSX\.exe";
62-
if (Regex.IsMatch(fileContent, pattern, RegexOptions.Compiled | RegexOptions.Multiline))
61+
RegexOptions regOptions = RegexOptions.Compiled | RegexOptions.Multiline;
62+
var runMatches = Regex.Matches(fileContent, @"[;]{0,1}Run(\d+).*", regOptions);
63+
int lastRun = 0;
64+
if (runMatches.Count > 0 && runMatches[runMatches.Count - 1].Groups.Count == 2)
65+
lastRun = Convert.ToInt32(runMatches[runMatches.Count - 1].Groups[1].Value);
66+
67+
var runIfMatches = Regex.Matches(fileContent, @"[;]{0,1}RunIf(\d+).*", regOptions);
68+
int lastRunIf = 0;
69+
if (runIfMatches.Count > 0 && runIfMatches[runIfMatches.Count - 1].Groups.Count == 2)
70+
lastRunIf = Convert.ToInt32(runIfMatches[runIfMatches.Count - 1].Groups[1].Value);
71+
72+
if (Regex.IsMatch(fileContent, @"^[;]{0,1}Run(\d+).*WorkingTitle2GSX\.exe", regOptions))
6373
{
64-
fileContent = Regex.Replace(fileContent, pattern, $"RunIf$1={programParam},KILL,{Parameters.binPath}", RegexOptions.Compiled | RegexOptions.Multiline);
74+
fileContent = Regex.Replace(fileContent, @"^[;]{0,1}Run(\d+).*WorkingTitle2GSX\.exe", $"RunIf{lastRunIf + 1}={programParam},KILL,{Parameters.binPath}", regOptions);
6575
File.WriteAllText(regPath, fileContent, Encoding.Default);
6676
result = true;
6777
}
68-
else
78+
else if (Regex.IsMatch(fileContent, @"^[;]{0,1}RunIf(\d+).*WorkingTitle2GSX\.exe", regOptions))
6979
{
70-
int posLastRunBegin = fileContent.LastIndexOf("RunIf");
71-
int posLastRunEnd = fileContent.IndexOf('\n', posLastRunBegin);
72-
int lastIndex = Convert.ToInt32(fileContent.Substring(posLastRunBegin + 5, 1));
73-
fileContent = fileContent.Insert(posLastRunEnd + 1, $"RunIf{lastIndex + 1}={programParam},KILL,{Parameters.binPath}\r\n");
80+
fileContent = Regex.Replace(fileContent, @"^[;]{0,1}RunIf(\d+).*WorkingTitle2GSX\.exe", $"RunIf$1={programParam},KILL,{Parameters.binPath}", regOptions);
7481
File.WriteAllText(regPath, fileContent, Encoding.Default);
7582
result = true;
7683
}
84+
else
85+
{
86+
int index = -1;
87+
if (runIfMatches.Count > 0 && runMatches.Count > 0)
88+
{
89+
index = runIfMatches[runIfMatches.Count - 1].Index + runIfMatches[runIfMatches.Count - 1].Length;
90+
if (runMatches[runMatches.Count - 1].Index > runIfMatches[runIfMatches.Count - 1].Index)
91+
index = runMatches[runMatches.Count - 1].Index + runMatches[runMatches.Count - 1].Length;
92+
}
93+
else if (runIfMatches.Count > 0)
94+
index = runIfMatches[runIfMatches.Count - 1].Index + runIfMatches[runIfMatches.Count - 1].Length;
95+
else if (runMatches.Count > 0)
96+
index = runMatches[runMatches.Count - 1].Index + runMatches[runMatches.Count - 1].Length;
97+
98+
if (index > 0)
99+
{
100+
fileContent = fileContent.Insert(index + 1, $"RunIf{lastRunIf + 1}={programParam},KILL,{Parameters.binPath}\r\n");
101+
File.WriteAllText(regPath, fileContent, Encoding.Default);
102+
result = true;
103+
}
104+
else
105+
{
106+
fileContent = Regex.Replace(fileContent, @"^\[Programs\]\r\n", $"[Programs]\r\nRunIf{lastRunIf + 1}={programParam},KILL,{Parameters.binPath}\r\n", regOptions);
107+
File.WriteAllText(regPath, fileContent, Encoding.Default);
108+
result = true;
109+
}
110+
}
77111
}
78112
}
79113
}

Installer/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@
4949
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
5050
// indem Sie "*" wie unten gezeigt eingeben:
5151
// [assembly: AssemblyVersion("1.0.*")]
52-
[assembly: AssemblyVersion("0.4.0.0")]
53-
[assembly: AssemblyFileVersion("0.4.0.0")]
52+
[assembly: AssemblyVersion("0.4.1.0")]
53+
[assembly: AssemblyFileVersion("0.4.1.0")]

WorkingTitle2GSX/WorkingTitle2GSX.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageIcon>logo.png</PackageIcon>
1515
<RepositoryUrl>https://github.com/Fragtality/WorkingTitle2GSX</RepositoryUrl>
1616
<PackageProjectUrl>https://github.com/Fragtality/WorkingTitle2GSX</PackageProjectUrl>
17-
<Version>0.4.0</Version>
17+
<Version>0.4.1</Version>
1818
<StartupObject>WorkingTitle2GSX.App</StartupObject>
1919
</PropertyGroup>
2020

0 commit comments

Comments
 (0)