Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
- Potential bugfix for UnauthorizedAccessException while applying a p…
Browse files Browse the repository at this point in the history
…atch

- Potential bugfixes for CookieAwareWebClient
- Improved the documentation and the tutorials
  • Loading branch information
yasirkula committed Mar 8, 2020
1 parent b504156 commit 9f48c5b
Show file tree
Hide file tree
Showing 18 changed files with 295 additions and 333 deletions.
Binary file modified Plugins/SimplePatchTool/DLL/SimplePatchTool.dll
Binary file not shown.
Binary file modified Plugins/SimplePatchTool/DLL/SimplePatchToolSecurity.dll
Binary file not shown.
47 changes: 31 additions & 16 deletions Plugins/SimplePatchTool/Demo/LauncherDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace SimplePatchToolUnity
{
[HelpURL( "https://github.com/yasirkula/UnitySimplePatchTool" )]
[HelpURL( "https://github.com/yasirkula/UnitySimplePatchTool#launcherdemo" )]
public class LauncherDemo : MonoBehaviour
{
// SimplePatchTool works on only standalone platforms
Expand All @@ -26,19 +26,19 @@ public class LauncherDemo : MonoBehaviour
private string launcherVersionInfoURL;

[SerializeField]
[Tooltip( "Main app's VersionInfo URL (to patch the mainAppSubdirectory)" )]
[Tooltip( "Main app's VersionInfo URL (to patch Main App Subdirectory)" )]
private string mainAppVersionInfoURL;

[SerializeField]
[Tooltip( "Subdirectory in which the main app resides" )]
private string mainAppSubdirectory = "MainApp";

[SerializeField]
[Tooltip( "The file in mainAppSubdirectory that will be launched when Play is pressed" )]
[Tooltip( "The file in Main App Subdirectory that will be launched when Play is pressed" )]
private string mainAppExecutable = "MyApp.exe";

[SerializeField]
[Tooltip( "Name of the self patcher executable" )]
[Tooltip( "Name of the self patcher's executable" )]
private string selfPatcherExecutable = "SelfPatcher.exe";

[SerializeField]
Expand All @@ -48,12 +48,12 @@ public class LauncherDemo : MonoBehaviour
[Header( "XML Verifier Keys (Optional)" )]
[SerializeField]
[TextArea]
[Tooltip( "Public RSA key that will be used to verify downloaded VersionInfo'es" )]
[Tooltip( "Public RSA key that will be used to verify downloaded VersionInfo.info" )]
private string versionInfoRSA;

[SerializeField]
[TextArea]
[Tooltip( "Public RSA key that will be used to verify downloaded PatchInfo'es" )]
[Tooltip( "Public RSA key that will be used to verify downloaded PatchInfo.info" )]
private string patchInfoRSA;

[Header( "Other Variables" )]
Expand Down Expand Up @@ -111,8 +111,22 @@ public class LauncherDemo : MonoBehaviour

private bool isPatchingLauncher;

#if UNITY_EDITOR
private readonly bool isEditor = true;
#else
private readonly bool isEditor = false;
#endif

private void Awake()
{
if( isEditor )
{
Debug.LogWarning( "Can't test the launcher on Editor!" );
Destroy( this );

return;
}

launcherVersionInfoURL = launcherVersionInfoURL.Trim();
mainAppVersionInfoURL = mainAppVersionInfoURL.Trim();
patchNotesURL = patchNotesURL.Trim();
Expand Down Expand Up @@ -182,25 +196,26 @@ private void Awake()
StartMainAppPatch( true );
}

private void OnDestroy()
{
if( patcher != null )
{
// Stop the patcher since this script can no longer control it
patcher.SetListener( null );
patcher.Cancel();
patcher = null;
}
}

private void PatchButtonClicked()
{
#if UNITY_EDITOR
Debug.LogWarning( "Can't test the launcher on Editor!" );
return;
#else
if( patcher != null && !patcher.IsRunning )
ExecutePatch();
#endif
}

private void RepairButtonClicked()
{
#if UNITY_EDITOR
Debug.LogWarning( "Can't test the launcher on Editor!" );
return;
#else
StartMainAppPatch( false );
#endif
}

private void PlayButtonClicked()
Expand Down
29 changes: 18 additions & 11 deletions Plugins/SimplePatchTool/Demo/MultiGameLauncherDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace SimplePatchToolUnity
{
[HelpURL( "https://github.com/yasirkula/UnitySimplePatchTool" )]
[HelpURL( "https://github.com/yasirkula/UnitySimplePatchTool#multigamelauncherdemo" )]
public class MultiGameLauncherDemo : MonoBehaviour
{
// SimplePatchTool works on only standalone platforms
Expand Down Expand Up @@ -64,7 +64,7 @@ public void TrimLinks()
private string launcherVersionInfoURL;

[SerializeField]
[Tooltip( "Name of the self patcher executable" )]
[Tooltip( "Name of the self patcher's executable" )]
private string selfPatcherExecutable = "SelfPatcher.exe";

[SerializeField]
Expand All @@ -82,12 +82,12 @@ public void TrimLinks()
[Header( "XML Verifier Keys (Optional)" )]
[SerializeField]
[TextArea]
[Tooltip( "Public RSA key that will be used to verify downloaded VersionInfo'es" )]
[Tooltip( "Public RSA key that will be used to verify downloaded VersionInfo.info" )]
private string versionInfoRSA;

[SerializeField]
[TextArea]
[Tooltip( "Public RSA key that will be used to verify downloaded PatchInfo'es" )]
[Tooltip( "Public RSA key that will be used to verify downloaded PatchInfo.info" )]
private string patchInfoRSA;

[Header( "Other Variables" )]
Expand Down Expand Up @@ -151,8 +151,22 @@ public void TrimLinks()

private MultiGameLauncherGameHolder[] gameHolders;

#if UNITY_EDITOR
private readonly bool isEditor = true;
#else
private readonly bool isEditor = false;
#endif

private void Awake()
{
if( isEditor )
{
Debug.LogWarning( "Can't test the launcher on Editor!" );
Destroy( this );

return;
}

launcherVersionInfoURL = launcherVersionInfoURL.Trim();
patchNotesURL = patchNotesURL.Trim();
forumURL = forumURL.Trim();
Expand Down Expand Up @@ -199,9 +213,7 @@ private void Awake()
StartCoroutine( FetchPatchNotes() );

// Can't test the launcher on Editor
#if !UNITY_EDITOR
StartLauncherPatch();
#endif
}

private void PlayButtonClicked( MultiGameLauncherGameHolder gameHolder )
Expand All @@ -215,12 +227,7 @@ private void PlayButtonClicked( MultiGameLauncherGameHolder gameHolder )

private void PatchButtonClicked( MultiGameLauncherGameHolder gameHolder )
{
#if UNITY_EDITOR
Debug.LogWarning( "Can't test the launcher on Editor!" );
return;
#else
ExecutePatch( gameHolder );
#endif
}

private void ForumButtonClicked()
Expand Down
8 changes: 4 additions & 4 deletions Plugins/SimplePatchTool/Demo/PatcherControlPanelDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@

namespace SimplePatchToolUnity
{
[HelpURL( "https://github.com/yasirkula/UnitySimplePatchTool" )]
[HelpURL( "https://github.com/yasirkula/UnitySimplePatchTool#patchercontrolpaneldemo" )]
public class PatcherControlPanelDemo : MonoBehaviour
{
// SimplePatchTool works on only standalone platforms
#if UNITY_EDITOR || UNITY_STANDALONE
#pragma warning disable 0649
[SerializeField]
[Tooltip( "Name of the self patcher executable" )]
[Tooltip( "Name of the self patcher's executable" )]
private string selfPatcherExecutable = "SelfPatcher.exe";

[Header( "XML Verifier Keys (Optional)" )]
[SerializeField]
[TextArea]
[Tooltip( "Public RSA key that will be used to verify downloaded VersionInfo'es" )]
[Tooltip( "Public RSA key that will be used to verify downloaded VersionInfo.info" )]
private string versionInfoRSA;

[SerializeField]
[TextArea]
[Tooltip( "Public RSA key that will be used to verify downloaded PatchInfo'es" )]
[Tooltip( "Public RSA key that will be used to verify downloaded PatchInfo.info" )]
private string patchInfoRSA;

[Header( "Other Variables" )]
Expand Down
12 changes: 12 additions & 0 deletions Plugins/SimplePatchTool/Demo/PatcherUI.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ GameObject:
- component: {fileID: 4232169956780676}
- component: {fileID: 114775860479319828}
- component: {fileID: 114005093399266698}
- component: {fileID: 114910840848650198}
m_Layer: 0
m_Name: EventSystem
m_TagString: Untagged
Expand Down Expand Up @@ -888,6 +889,17 @@ MonoBehaviour:
m_Calls: []
m_TypeName: UnityEngine.UI.Slider+SliderEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!114 &114910840848650198
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1877403372044416}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1327945023, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!222 &222066668790139806
CanvasRenderer:
m_ObjectHideFlags: 1
Expand Down
31 changes: 21 additions & 10 deletions Plugins/SimplePatchTool/Demo/SelfPatchingAppDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace SimplePatchToolUnity
{
[HelpURL( "https://github.com/yasirkula/UnitySimplePatchTool" )]
[HelpURL( "https://github.com/yasirkula/UnitySimplePatchTool#selfpatchingappdemo" )]
public class SelfPatchingAppDemo : MonoBehaviour
{
// SimplePatchTool works on only standalone platforms
Expand All @@ -20,22 +20,22 @@ public class SelfPatchingAppDemo : MonoBehaviour
private string versionInfoURL;

[SerializeField]
[Tooltip( "While checking for updates:\ntrue: only version number is checked (faster)\nfalse: hashes and sizes of the files are checked (verifies file integrity)" )]
[Tooltip( "While checking for updates:\ntrue: only version number is checked (faster)\nfalse: hashes and sizes of the files are checked (verifying integrity of files)" )]
private bool checkVersionOnly = true;

[SerializeField]
[Tooltip( "Name of the self patcher executable" )]
[Tooltip( "Name of the self patcher's executable" )]
private string selfPatcherExecutable = "SelfPatcher.exe";

[Header( "XML Verifier Keys (Optional)" )]
[SerializeField]
[TextArea]
[Tooltip( "Public RSA key that will be used to verify downloaded VersionInfo'es" )]
[Tooltip( "Public RSA key that will be used to verify downloaded VersionInfo.info" )]
private string versionInfoRSA;

[SerializeField]
[TextArea]
[Tooltip( "Public RSA key that will be used to verify downloaded PatchInfo'es" )]
[Tooltip( "Public RSA key that will be used to verify downloaded PatchInfo.info" )]
private string patchInfoRSA;

[Header( "Other Variables" )]
Expand All @@ -56,8 +56,16 @@ public class SelfPatchingAppDemo : MonoBehaviour
private SimplePatchTool patcher;
private static bool executed = false;

#if UNITY_EDITOR
private readonly bool isEditor = true;
#else
private readonly bool isEditor = false;
#endif

private void Awake()
{
// SimplePatchTool can continue running even when the scene changes, but we don't want to run another instance
// of SimplePatchTool if we return to this GameObject's scene. We run SimplePatchTool only once
if( executed )
{
Destroy( gameObject );
Expand All @@ -67,17 +75,20 @@ private void Awake()
executed = true;
updatePanel.SetActive( false );

#if UNITY_EDITOR
Debug.LogWarning( "Can't self patch while testing on editor" );
Destroy( gameObject );
#else
if( isEditor )
{
Debug.LogWarning( "Can't self patch while testing on editor" );
Destroy( gameObject );

return;
}

InitializePatcher();

updateButton.onClick.AddListener( UpdateButtonClicked );
dismissButton.onClick.AddListener( DismissButtonClicked );

DontDestroyOnLoad( gameObject );
#endif
}

private void InitializePatcher()
Expand Down
8 changes: 3 additions & 5 deletions Plugins/SimplePatchTool/Editor/PatcherEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,16 @@ private void OnGUI()
project = new ProjectManager( projectRootPath );
project.CreateProject();

ProjectInfo projectInfo = PatchUtils.GetProjectInfoFromPath( project.projectInfoPath );
ProjectInfo projectInfo = project.LoadProjectInfo();
projectInfo.IgnoredPaths.Add( "*output_log.txt" );
PatchUtils.SerializeProjectInfoToXML( projectInfo, project.projectInfoPath );

SecurityUtils.CreateRSAKeyPairInDirectory( project.utilitiesPath );
project.SaveProjectInfo( projectInfo );

EditorApplication.update -= OnUpdate;
EditorApplication.update += OnUpdate;

CheckProjectExists();

EditorUtility.DisplayDialog( "Self Patcher Executable", "If this is a self patching app (i.e. this app will update itself), you'll need to generate a self patcher executable. See README for more info.", "Got it!" );
EditorUtility.DisplayDialog( "Self Patcher", "If this is a self patching app (i.e. this app will update itself), you'll need to generate a self patcher. See README for more info.", "Got it!" );
}

GUI.enabled = ( project == null || !project.IsRunning ) && projectExists.HasValue && projectExists.Value;
Expand Down
6 changes: 3 additions & 3 deletions Plugins/SimplePatchTool/Editor/PatcherEditorLegacy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void DrawUpdateTab()
}

if( GUILayout.Button( "Help", GUILayout.Height( 25f ) ) )
Application.OpenURL( "https://github.com/yasirkula/SimplePatchTool/wiki/Legacy:-Updating-Download-Links" );
Application.OpenURL( "https://github.com/yasirkula/SimplePatchTool/wiki/Legacy:-Updating-Download-Links#via-unity-plugin" );
}

private void DrawSecurityTab()
Expand Down Expand Up @@ -259,8 +259,8 @@ private void DrawSecurityTab()
string publicKey, privateKey;
SecurityUtils.CreateRSAKeyPair( out publicKey, out privateKey );

File.WriteAllText( Path.Combine( selectedPath, "rsa_public.bytes" ), publicKey );
File.WriteAllText( Path.Combine( selectedPath, "rsa_private.bytes" ), privateKey );
File.WriteAllText( Path.Combine( selectedPath, "public.key" ), publicKey );
File.WriteAllText( Path.Combine( selectedPath, "private.key" ), privateKey );

AssetDatabase.Refresh();
}
Expand Down
7 changes: 0 additions & 7 deletions Plugins/SimplePatchTool/Editor/PatcherPostProcessBuild.cs

This file was deleted.

12 changes: 0 additions & 12 deletions Plugins/SimplePatchTool/Editor/PatcherPostProcessBuild.cs.meta

This file was deleted.

Loading

0 comments on commit 9f48c5b

Please sign in to comment.