From 8cab1e7de7f8c46854ecfca630266b68c9c1bda1 Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Wed, 25 Jul 2018 12:51:26 +0200 Subject: [PATCH 1/5] Implementation --- .../Editor/PatcherManifestCreator.cs | 32 +++++++++++++---- .../Editor/UnixLaunchScriptCreator.cs | 35 +++++++++++++++++++ .../Editor/UnixLaunchScriptCreator.cs.meta | 12 +++++++ .../Editor/patcher.template.sh | 19 ++++++++++ .../Editor/patcher.template.sh.meta | 8 +++++ 5 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs create mode 100644 Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs.meta create mode 100644 Assets/PatchKit Patcher/Editor/patcher.template.sh create mode 100644 Assets/PatchKit Patcher/Editor/patcher.template.sh.meta diff --git a/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs b/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs index b7999af8..227f973f 100644 --- a/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs +++ b/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs @@ -40,17 +40,35 @@ private static void PostProcessBuild(BuildTarget buildTarget, string buildPath) File.WriteAllText(manifestPath, manifestContent); } - private static Manifest WindowsManifest(string buildPath) - { - return CommonManifest(buildPath); - } - private static Manifest LinuxManifest(string buildPath) { - return CommonManifest(buildPath); + string patcherExe = Path.GetFileName(buildPath); + string launchScript = UnixLaunchScriptCreator.LaunchScriptName; + + return new Manifest { + ExeFileName = string.Format("\"{{exedir}}/{0}\"", patcherExe), + ExeArguments = "--installdir \"{installdir}\" --secret \"{secret}\"", + + Version = ManifestVersion, + Target = "bash", + Arguments = new Manifest.Argument[] { + new Manifest.Argument { Value = new string[] { + "{exedir}" + launchScript + }}, + new Manifest.Argument { Value = new string[] { + "{exedir}", + patcherExe, + "{secret}", + "{installdir}" + }}, + new Manifest.Argument { Value = new string[] { + "{lockfile}" + }} + } + }; } - private static Manifest CommonManifest(string buildPath) + private static Manifest WindowsManifest(string buildPath) { string targetFile = Path.GetFileName(buildPath); return new Manifest { diff --git a/Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs b/Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs new file mode 100644 index 00000000..e9e4257e --- /dev/null +++ b/Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs @@ -0,0 +1,35 @@ +using System.IO; +using JetBrains.Annotations; +using Newtonsoft.Json; +using UnityEditor; +using UnityEditor.Callbacks; + +namespace PatchKit.Unity.Editor +{ + public static class UnixLaunchScriptCreator + { + private const string LaunchScriptContentFile = "Assets/PatchKit Patcher/Editor/patcher.template.sh"; + public const string LaunchScriptName = "run.sh"; + + public static string LaunchScriptPath(string buildPath) + { + return Path.Combine(Path.GetDirectoryName(buildPath), LaunchScriptName); + } + + [PostProcessBuild, UsedImplicitly] + private static void PostProcessBuild(BuildTarget buildTarget, string buildPath) + { + if (buildTarget != BuildTarget.StandaloneLinux64 && + buildTarget != BuildTarget.StandaloneLinux && + buildTarget != BuildTarget.StandaloneLinuxUniversal) + { + return; + } + + string launchScriptPath = LaunchScriptPath(buildPath); + string launchScriptContent = File.ReadAllText(LaunchScriptContentFile); + + File.WriteAllText(launchScriptPath, launchScriptContent); + } + } +} \ No newline at end of file diff --git a/Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs.meta b/Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs.meta new file mode 100644 index 00000000..f5a6fdc5 --- /dev/null +++ b/Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5d3e8400c0d374f7b8ab256464ab130a +timeCreated: 1532511924 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/PatchKit Patcher/Editor/patcher.template.sh b/Assets/PatchKit Patcher/Editor/patcher.template.sh new file mode 100644 index 00000000..0090c69e --- /dev/null +++ b/Assets/PatchKit Patcher/Editor/patcher.template.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +EXEDIR=$1 +PATCHER_EXE=$2 +SECRET=$3 +INSTALLDIR=$4 +LOCKFILE=$5 + +LD_DIRS=`find $EXEDIR -name "x86_64" -printf "%p:"` +LD_DIRS=$LD_DIRS`find $EXEDIR -name "x86" -printf "%p:"` + +export LD_LIBRARY_PATH=$LD_DIRS + +if [ -n $LOCKFILE ] +then + $EXEDIR/$PATCHER_EXE --installdir $INSTALLDIR --secret $SECRET --lockfile $LOCKFILE +else + $EXEDIR/$PATCHER_EXE --installdir $INSTALLDIR --secret $SECRET +fi \ No newline at end of file diff --git a/Assets/PatchKit Patcher/Editor/patcher.template.sh.meta b/Assets/PatchKit Patcher/Editor/patcher.template.sh.meta new file mode 100644 index 00000000..c7b9eb13 --- /dev/null +++ b/Assets/PatchKit Patcher/Editor/patcher.template.sh.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0dae67bed3a1246349e558cf3f16f036 +timeCreated: 1532513803 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: From d19d3001637b46b51818b8a41804d5d91e0c3018 Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Wed, 25 Jul 2018 13:47:41 +0200 Subject: [PATCH 2/5] Using sh instead of bash --- Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs | 2 +- Assets/PatchKit Patcher/Editor/patcher.template.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs b/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs index 227f973f..9684dbdb 100644 --- a/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs +++ b/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs @@ -50,7 +50,7 @@ private static Manifest LinuxManifest(string buildPath) ExeArguments = "--installdir \"{installdir}\" --secret \"{secret}\"", Version = ManifestVersion, - Target = "bash", + Target = "sh", Arguments = new Manifest.Argument[] { new Manifest.Argument { Value = new string[] { "{exedir}" + launchScript diff --git a/Assets/PatchKit Patcher/Editor/patcher.template.sh b/Assets/PatchKit Patcher/Editor/patcher.template.sh index 0090c69e..6a22ee5f 100644 --- a/Assets/PatchKit Patcher/Editor/patcher.template.sh +++ b/Assets/PatchKit Patcher/Editor/patcher.template.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh EXEDIR=$1 PATCHER_EXE=$2 From e4661d9fecc1b20efa75a7f022b2aee209d7d98d Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Wed, 25 Jul 2018 18:22:14 +0200 Subject: [PATCH 3/5] Missing slash --- Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs b/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs index 9684dbdb..44d648e8 100644 --- a/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs +++ b/Assets/PatchKit Patcher/Editor/PatcherManifestCreator.cs @@ -53,7 +53,7 @@ private static Manifest LinuxManifest(string buildPath) Target = "sh", Arguments = new Manifest.Argument[] { new Manifest.Argument { Value = new string[] { - "{exedir}" + launchScript + "{exedir}/" + launchScript }}, new Manifest.Argument { Value = new string[] { "{exedir}", From 5e5458cccfda609c0f23f266b3b9dc65d0e3e710 Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Wed, 25 Jul 2018 18:23:07 +0200 Subject: [PATCH 4/5] Copying the file instead of reading and writing it's contents --- Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs b/Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs index e9e4257e..4746dd1d 100644 --- a/Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs +++ b/Assets/PatchKit Patcher/Editor/UnixLaunchScriptCreator.cs @@ -27,9 +27,8 @@ private static void PostProcessBuild(BuildTarget buildTarget, string buildPath) } string launchScriptPath = LaunchScriptPath(buildPath); - string launchScriptContent = File.ReadAllText(LaunchScriptContentFile); - File.WriteAllText(launchScriptPath, launchScriptContent); + File.Copy(LaunchScriptContentFile, launchScriptPath); } } } \ No newline at end of file From 6eb73028ccbf1210990ffd3a0d5abdf296f5c4e3 Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Wed, 25 Jul 2018 18:56:14 +0200 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3393683..815f67cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Animated progress bar during initialization and connecting - New manifest format support - Sending 'patcher_started' event to Statistics Reporting Service +- A launch script on Linux platforms ### Changed - Update API servers configuration