Skip to content

Commit

Permalink
Merge pull request #153 from Settlers4Modding/bug/fix-temp-folder-issue
Browse files Browse the repository at this point in the history
Update Download path for Settlers United
  • Loading branch information
XanatosX authored Nov 2, 2021
2 parents 5edb7bc + 83b49ac commit db2c9ff
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 33 deletions.
9 changes: 9 additions & 0 deletions src/CommunityPatchLauncher/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@
<setting name="EditorBaseFolder" serializeAs="String">
<value>Editor/</value>
</setting>
<setting name="ConfigBaseFolder" serializeAs="String">
<value>Config/</value>
</setting>
<setting name="SettlersUnitedDownloadName" serializeAs="String">
<value>SettlersUnitedSetup.exe</value>
</setting>
<setting name="SettlersUnitedDownloadUri" serializeAs="String">
<value>https://files.settlers-united.com/Settlers-United.exe</value>
</setting>
</CommunityPatchLauncher.Properties.Settings>
</userSettings>
</configuration>
28 changes: 26 additions & 2 deletions src/CommunityPatchLauncher/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/CommunityPatchLauncher/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,14 @@
<Setting Name="EditorBaseFolder" Type="System.String" Scope="User">
<Value Profile="(Default)">Editor/</Value>
</Setting>
<Setting Name="ConfigBaseFolder" Type="System.String" Scope="User">
<Value Profile="(Default)">Config/</Value>
</Setting>
<Setting Name="SettlersUnitedDownloadName" Type="System.String" Scope="User">
<Value Profile="(Default)">SettlersUnitedSetup.exe</Value>
</Setting>
<Setting Name="SettlersUnitedDownloadUri" Type="System.String" Scope="User">
<Value Profile="(Default)">https://files.settlers-united.com/Settlers-United.exe</Value>
</Setting>
</Settings>
</SettingsFile>
66 changes: 35 additions & 31 deletions src/CommunityPatchLauncher/Windows/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Net;
using System.Windows;

using CommunityPatchLauncher.ViewModels;
using System.IO.Compression;
using System.Threading.Tasks;
using System.IO;
Expand Down Expand Up @@ -51,21 +50,29 @@ private void UpgradetoSettlersUnited(object sender, RoutedEventArgs e)
private async Task UpgradetoSettlersUnited()
{
await ZipInstallerAsync();
string URI = "https://files.settlers-united.com/Settlers-United.exe";
DownloadFileAsync(URI, "SettlersUnitedSetup.exe", Properties.Resources.Setters_United_Beta, true);
DownloadFileAsync(
Properties.Settings.Default.SettlersUnitedDownloadUri,
GetDownloadedFileName()
);
}
private void DownloadFileAsync(string URI, string File, string Name, bool SettlersUnited = false)

private string GetDownloadedFileName()
{
return Path.Combine(Path.GetTempPath(), Properties.Settings.Default.SettlersUnitedDownloadName);
}

private void DownloadFileAsync(string uri, string file)
{
DownlaodPanel.Visibility = Visibility.Visible;
DownlaodLabel.Content = Properties.Resources.Download_United_Update + Environment.NewLine + Name;
DownlaodLabel.Content = Properties.Resources.Download_United_Update + Environment.NewLine + Properties.Resources.Setters_United_Beta;

try
{
using (WebClient wc = new WebClient())
{
wc.DownloadProgressChanged += DownloadProgressChanged;
wc.DownloadFileCompleted += DownloadFileEventCompletedUnited;
wc.DownloadFileAsync(new Uri(URI), File);
wc.DownloadFileAsync(new Uri(uri), file);
}
}
catch (Exception)
Expand All @@ -78,12 +85,9 @@ private void DownloadFileAsync(string URI, string File, string Name, bool Settle

private void DownloadFileEventCompletedUnited(object sender, AsyncCompletedEventArgs e)
{
//ToDo Install first HE!!! @Leonards05 | Pumpline#5578

var startInfo = new ProcessStartInfo
{
FileName = "SettlersUnitedSetup.exe",

FileName = GetDownloadedFileName(),
Verb = "runas"
};
try
Expand Down Expand Up @@ -117,7 +121,7 @@ public async Task ZipInstallerAsync()
{
string zipFilePath = @"assets\HistoryEdition.zip";

string InstallPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Ubisoft\Launcher\Installs\11785", "InstallDir", null);
string InstallPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Ubisoft\Launcher\Installs\11785", "InstallDir", null);

using (ZipArchive archive = await Task.Run(() => ZipFile.OpenRead(zipFilePath)))
{
Expand All @@ -132,7 +136,7 @@ public async Task ZipInstallerAsync()
}
try
{
if (entry.FullName.EndsWith(@".map", StringComparison.OrdinalIgnoreCase))
if (entry.FullName.EndsWith(@".map", StringComparison.OrdinalIgnoreCase))
{
if (!File.Exists(InstallPath + completeFileName))
{
Expand All @@ -152,31 +156,31 @@ public async Task ZipInstallerAsync()
}
else
{
if (!entry.FullName.EndsWith(@"/", StringComparison.OrdinalIgnoreCase))
if (!entry.FullName.EndsWith(@"/", StringComparison.OrdinalIgnoreCase))
{
await Task.Run(() =>
{
await Task.Run(() =>
try
{
try
{
entry.ExtractToFile(completeFileName, true);
}
catch
{
MessageBox.Show("Error", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(0);
}
});
}
}

entry.ExtractToFile(completeFileName, true);
}
catch
{
MessageBox.Show("Error", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(0);
}
});
}
}

}
catch (Exception)
{
}
}
}
}

#endregion
}
}

#endregion
}
}

0 comments on commit db2c9ff

Please sign in to comment.