-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
412 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace GotoUdon.Editor | ||
{ | ||
public class ReleaseAsset | ||
{ | ||
public string Name { get; set; } | ||
public string DownloadUrl { get; set; } | ||
public bool IsUnityPackage => Name.EndsWith(".unitypackage"); | ||
|
||
public string AsFileName(string path) | ||
{ | ||
return path.EndsWith("/") ? path + Name : path + "/" + Name; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace GotoUdon.Editor | ||
{ | ||
public class ReleaseInfo | ||
{ | ||
public string Name { get; set; } | ||
public string Version { get; set; } | ||
public string Description { get; set; } | ||
public List<ReleaseAsset> Assets { get; set; } | ||
|
||
public ReleaseAsset UnityPackage | ||
{ | ||
get | ||
{ | ||
foreach (ReleaseAsset asset in Assets) | ||
{ | ||
if (asset.IsUnityPackage) | ||
{ | ||
return asset; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} | ||
|
||
// supports only simple versions like "v1.0.0" | ||
public bool IsNewerThan(string version) | ||
{ | ||
if (version.Equals(Version)) | ||
{ | ||
return false; | ||
} | ||
|
||
string[] versionNumbers = ExtractVersionComponents(version); | ||
string[] thisVersionNumbers = ExtractVersionComponents(Version); | ||
|
||
for (int i = 0; i < Math.Min(versionNumbers.Length, thisVersionNumbers.Length); i++) | ||
{ | ||
if (int.Parse(thisVersionNumbers[i]) > int.Parse(versionNumbers[i])) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
// eg: 1.0.1 vs 1.0 | ||
return thisVersionNumbers.Length > versionNumbers.Length; | ||
} | ||
|
||
private string[] ExtractVersionComponents(string version) | ||
{ | ||
if (version.StartsWith("v")) | ||
{ | ||
version = version.Substring(1); | ||
} | ||
|
||
return version.Split('.'); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace GotoUdon.Editor | ||
{ | ||
public class ReleaseResponse | ||
{ | ||
public string Error { get; set; } | ||
public ReleaseInfo ReleaseInfo { get; set; } | ||
public bool IsError => Error != null; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
Assets/GotoUdon/Editor/VersionChecker/ReleaseResponse.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using System.IO; | ||
using GotoUdon.Utils; | ||
using UnityEngine; | ||
using UnityEngine.Networking; | ||
|
||
namespace GotoUdon.Editor.VersionChecker | ||
{ | ||
public class Updater | ||
{ | ||
public static void Update(string path, ReleaseAsset asset, Action<UpdateResult> callback) | ||
{ | ||
GotoLog.Log($"Downloading update ({asset.Name}) from {asset.DownloadUrl}"); | ||
UnityWebRequest www = UnityWebRequest.Get(asset.DownloadUrl); | ||
try | ||
{ | ||
www.downloadHandler = new DownloadHandlerFile(Path.Combine(Application.dataPath, asset.AsFileName(path))); | ||
UnityWebRequestAsyncOperation action = www.SendWebRequest(); | ||
action.completed += operation => | ||
{ | ||
UnityWebRequest request = action.webRequest; | ||
var responseCode = request.responseCode; | ||
if (responseCode != 200) | ||
{ | ||
GotoLog.Error("Failed to download update: " + request.error); | ||
callback(new UpdateResult {Error = "Failed to download" + request.error}); | ||
www.Dispose(); | ||
return; | ||
} | ||
|
||
callback(new UpdateResult {DownloadPath = "Assets/" + asset.AsFileName(path)}); | ||
www.Dispose(); | ||
}; | ||
} | ||
catch (Exception exception) | ||
{ | ||
GotoLog.Exception("Failed to request for update: " + exception.Message, exception); | ||
www.Dispose(); | ||
} | ||
} | ||
|
||
public class UpdateResult | ||
{ | ||
public string Error { get; set; } | ||
public string DownloadPath { get; set; } | ||
public bool IsError => Error != null; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.