Skip to content

Commit

Permalink
Merge pull request #140 from ChronosWS/BletchChanges
Browse files Browse the repository at this point in the history
ASM 298 Changes
  • Loading branch information
Bletch1971 authored Aug 11, 2017
2 parents ae3081e + 4a2f10b commit 6b849fa
Show file tree
Hide file tree
Showing 26 changed files with 825 additions and 251 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Plugin.Discord.UnitTests/bin/
Plugin.Discord.UnitTests/obj/
QueryMaster/bin/
QueryMaster/obj/
ServerManager.Updater/bin/
ServerManager.Updater/obj/
SteamKit2/bin/
SteamKit2/obj/
WebAPI/bin/
Expand Down
14 changes: 14 additions & 0 deletions ARK Dedicated Server Tool.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerManager.Updater", "ServerManager.Updater\ServerManager.Updater.csproj", "{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -151,6 +153,18 @@ Global
{8D13FC88-9508-4C3A-8ED0-F7BD46E343CC}.Release|x64.Build.0 = Release|Any CPU
{8D13FC88-9508-4C3A-8ED0-F7BD46E343CC}.Release|x86.ActiveCfg = Release|Any CPU
{8D13FC88-9508-4C3A-8ED0-F7BD46E343CC}.Release|x86.Build.0 = Release|Any CPU
{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}.Debug|x64.ActiveCfg = Debug|Any CPU
{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}.Debug|x64.Build.0 = Debug|Any CPU
{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}.Debug|x86.ActiveCfg = Debug|Any CPU
{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}.Debug|x86.Build.0 = Debug|Any CPU
{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}.Release|Any CPU.Build.0 = Release|Any CPU
{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}.Release|x64.ActiveCfg = Release|Any CPU
{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}.Release|x64.Build.0 = Release|Any CPU
{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}.Release|x86.ActiveCfg = Release|Any CPU
{3E0C9EE6-780F-4FEF-BA03-E38062A5FDB6}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
9 changes: 7 additions & 2 deletions ARK Server Manager/ARK Server Manager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<PublisherName>Ark Server Manager</PublisherName>
<OpenBrowserOnPublish>false</OpenBrowserOnPublish>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>1.0.298.%2a</ApplicationVersion>
<ApplicationVersion>1.0.299.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>false</BootstrapperEnabled>
Expand Down Expand Up @@ -164,6 +164,7 @@
<Compile Include="Common\Serialization\IniFile.cs" />
<Compile Include="Common\Serialization\IniKey.cs" />
<Compile Include="Common\Serialization\IniSection.cs" />
<Compile Include="Common\Utils\IOUtils.cs" />
<Compile Include="Windows\AddSteamUserWindow.xaml.cs">
<DependentUpon>AddSteamUserWindow.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -463,7 +464,7 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Config.settings</DependentUpon>
</Compile>
<Compile Include="Common\Lib\Updater.cs" />
<Compile Include="Common\Lib\SteamCmdUpdater.cs" />
<Compile Include="Lib\ServerManager.cs" />
<Compile Include="Windows\MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
Expand Down Expand Up @@ -529,6 +530,10 @@
<Project>{4ca9c894-518f-42d7-bbe2-cfdfe7a03f8a}</Project>
<Name>QueryMaster</Name>
</ProjectReference>
<ProjectReference Include="..\ServerManager.Updater\ServerManager.Updater.csproj">
<Project>{3e0c9ee6-780f-4fef-ba03-e38062a5fdb6}</Project>
<Name>ServerManager.Updater</Name>
</ProjectReference>
<ProjectReference Include="..\WPFSharp.Globalizer\WPFSharp.Globalizer.csproj">
<Project>{715461e8-4e54-4993-80a8-8e72892135e0}</Project>
<Name>WPFSharp.Globalizer</Name>
Expand Down
6 changes: 6 additions & 0 deletions ARK Server Manager/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@
<setting name="MapExtension" serializeAs="String">
<value>.ark</value>
</setting>
<setting name="UpdaterPrefix" serializeAs="String">
<value>ASM_</value>
</setting>
<setting name="UpdaterFile" serializeAs="String">
<value>ServerManagerUpdater.exe</value>
</setting>
</ARK_Server_Manager.Config>
</applicationSettings>
<userSettings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace ARK_Server_Manager.Lib
/// <summary>
/// Checks for an updates this program
/// </summary>
class Updater
class SteamCmdUpdater
{
public const string OUTPUT_PREFIX = "[UPDATER]";

Expand Down Expand Up @@ -56,9 +56,6 @@ public static Update AsCancelled(string statusKey)

enum Status
{
CheckForNewServerVersion,
DownloadNewServerVersion,
DownloadNewServerComplete,
CleaningSteamCmd,
DownloadingSteamCmd,
UnzippingSteamCmd,
Expand All @@ -71,20 +68,17 @@ enum Status
Dictionary<Status, Update> statuses = new Dictionary<Status, Update>()
{
{ Status.CleaningSteamCmd, new Update("AutoUpdater_Status_CleaningSteamCmd", 0) },
{ Status.DownloadingSteamCmd, new Update("AutoUpdater_Status_DownloadingSteamCmd", 0) },
{ Status.UnzippingSteamCmd, new Update("AutoUpdater_Status_UnzippingSteamCmd", 20) },
{ Status.RunningSteamCmd, new Update("AutoUpdater_Status_RunningSteamCmd", 40) },
{ Status.InstallSteamCmdComplete, new Update("AutoUpdater_Status_InstallSteamCmdComplete", 50) },
{ Status.CheckForNewServerVersion, new Update("AutoUpdater_Status_CheckForNewServerVersion", 50) },
{ Status.DownloadNewServerVersion, new Update("AutoUpdater_Status_DownloadNewServerVersion", 60) },
{ Status.DownloadNewServerComplete, new Update("AutoUpdater_Status_DownloadNewServerComplete", 90) },
{ Status.DownloadingSteamCmd, new Update("AutoUpdater_Status_DownloadingSteamCmd", 10) },
{ Status.UnzippingSteamCmd, new Update("AutoUpdater_Status_UnzippingSteamCmd", 30) },
{ Status.RunningSteamCmd, new Update("AutoUpdater_Status_RunningSteamCmd", 50) },
{ Status.InstallSteamCmdComplete, new Update("AutoUpdater_Status_InstallSteamCmdComplete", 80) },
{ Status.Complete, Update.AsCompleted("AutoUpdater_Status_Complete") },
{ Status.Cancelled, Update.AsCancelled("AutoUpdater_Status_Cancelled") }
};

public static bool IsAutoUpdateCacheEnabled => Config.Default.AutoUpdate_EnableUpdate && Config.Default.AutoUpdate_UpdatePeriod >= 0 && !string.IsNullOrWhiteSpace(Config.Default.AutoUpdate_CacheDir) && Directory.Exists(Config.Default.AutoUpdate_CacheDir);

public static string GetLogFolder() => Updater.NormalizePath(Path.Combine(Config.Default.DataDir, Config.Default.LogsDir));
public static string GetLogFolder() => IOUtils.NormalizePath(Path.Combine(Config.Default.DataDir, Config.Default.LogsDir));

public static Version GetServerVersion(string versionFile)
{
Expand All @@ -107,9 +101,7 @@ public static Version GetServerVersion(string versionFile)
return new Version(0, 0);
}

public static string GetSteamCmdFile() => NormalizePath(Path.Combine(Config.Default.DataDir, Config.Default.SteamCmdDir, Config.Default.SteamCmdExe));

public static string NormalizePath(string path) => Path.GetFullPath(new Uri(path).LocalPath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).ToLowerInvariant();
public static string GetSteamCmdFile() => IOUtils.NormalizePath(Path.Combine(Config.Default.DataDir, Config.Default.SteamCmdDir, Config.Default.SteamCmdExe));

#region SteamCMD
public async Task ReinstallSteamCmdAsync(IProgress<Update> reporter, CancellationToken cancellationToken)
Expand Down Expand Up @@ -226,68 +218,5 @@ public async void UpdateSteamCmdAsync(IProgress<Update> reporter, CancellationTo
}
}
#endregion

#region ASM Update
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool DeleteFile(string name);

private static bool Unblock(string fileName)
{
return DeleteFile(fileName + ":Zone.Identifier");
}

public static void UpdateASM(ProgressDelegate progressCallback = null)
{
var applicationZip = Path.Combine(Path.GetTempPath(), "ASMLatest.zip");
var extractPath = Path.Combine(Path.GetTempPath(), "ASMLatest");
var updateFilePath = Path.Combine(Path.GetTempPath(), "ASMUpdate.cmd");
var currentInstallPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var backupPath = currentInstallPath + "_bak";

// Grab the latest version
using (var client = new WebClient())
{
progressCallback?.Invoke(0, "Updater_ProgressMessage_DownloadLabel", true);
if (App.Instance.BetaVersion)
client.DownloadFile(Config.Default.LatestASMBetaDownloadUrl, applicationZip);
else
client.DownloadFile(Config.Default.LatestASMDownloadUrl, applicationZip);

progressCallback?.Invoke(0, "Updater_ProgressMessage_PrepareLabel", true);
Unblock(applicationZip);
}

try
{
// Delete the old extraction directory
Directory.Delete(extractPath, true);
}
catch { }

// Extract latest version to extraction directory
progressCallback?.Invoke(0, "Updater_ProgressMessage_ExtractLabel", true);
ZipFile.ExtractToDirectory(applicationZip, extractPath);

// Replace the current installation
var script = new StringBuilder();

script.AppendLine("timeout 10");
script.AppendLine($"rmdir /s /q {backupPath.AsQuoted()}");
script.AppendLine($"rename {currentInstallPath.AsQuoted()} {Path.GetFileName(backupPath).AsQuoted()}");
script.AppendLine($"xcopy /e /y {(extractPath + "\\*.*").AsQuoted()} {(currentInstallPath + "\\").AsQuoted()}");
script.AppendLine($"start \"\" {Assembly.GetExecutingAssembly().Location.AsQuoted()} {App.Instance.Args}");
script.AppendLine("exit");

progressCallback?.Invoke(0, "Updater_ProgressMessage_UpgradeLabel", true);

TaskUtils.RunOnUIThreadAsync(() =>
{
ScriptUtils.RunShellScript(nameof(UpdateASM), script.ToString(), withElevation: false, waitForExit: false);

Application.Current.Shutdown(0);
}).DoNotWait();
}
#endregion
}
}
20 changes: 20 additions & 0 deletions ARK Server Manager/Common/Utils/IOUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.IO;
using System.Runtime.InteropServices;

namespace ARK_Server_Manager.Lib
{
public static class IOUtils
{
[DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool DeleteFile(string name);

public static bool Unblock(string fileName)
{
return DeleteFile(fileName + ":Zone.Identifier");
}

public static string NormalizePath(string path) => Path.GetFullPath(new Uri(path).LocalPath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).ToLowerInvariant();
}
}
18 changes: 18 additions & 0 deletions ARK Server Manager/Config.Designer.cs

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

6 changes: 6 additions & 0 deletions ARK Server Manager/Config.settings
Original file line number Diff line number Diff line change
Expand Up @@ -521,5 +521,11 @@
<Setting Name="MapExtension" Type="System.String" Scope="Application">
<Value Profile="(Default)">.ark</Value>
</Setting>
<Setting Name="UpdaterPrefix" Type="System.String" Scope="Application">
<Value Profile="(Default)">ASM_</Value>
</Setting>
<Setting Name="UpdaterFile" Type="System.String" Scope="Application">
<Value Profile="(Default)">ServerManagerUpdater.exe</Value>
</Setting>
</Settings>
</SettingsFile>
Loading

0 comments on commit 6b849fa

Please sign in to comment.