-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1151 from anatawa12/new-version-checks
New version checks
- Loading branch information
Showing
25 changed files
with
620 additions
and
171 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env node | ||
|
||
import { writeFileSync } from 'node:fs'; | ||
|
||
const baseUrl = process.argv[2]; | ||
const newVersion = process.argv[3]; | ||
const requiredUnity = "2019.4"; | ||
|
||
const supports2019 = requiredUnity.startsWith("2019"); | ||
|
||
if (supports2019) { | ||
writeFileSync("static/latest.txt", newVersion); | ||
} | ||
|
||
const existingLatest2Txt = await fetch(`${baseUrl}/latest2.txt`); | ||
if (!existingLatest2Txt.ok) throw new Error(`Failed to fetch latest2.txt: ${existingLatest2Txt.statusText}`); | ||
const existingLatest2 = await existingLatest2Txt.text(); | ||
|
||
const parsed = existingLatest2.trimEnd().split("\n").map(x => x.split(':')); | ||
|
||
const sameUnityIndex = parsed.findIndex(x => x[1] === requiredUnity); | ||
if (sameUnityIndex !== -1) { | ||
parsed[sameUnityIndex][0] = newVersion; | ||
} else { | ||
parsed.push([newVersion, requiredUnity]); | ||
} | ||
|
||
const newLatest2 = parsed.map(x => x.join(':') + '\n').join(''); | ||
|
||
writeFileSync("static/latest2.txt", newLatest2); |
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,108 @@ | ||
using System; | ||
using System.IO; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Anatawa12.AvatarOptimizer.CheckForUpdate | ||
{ | ||
[InitializeOnLoad] | ||
internal static class Checker | ||
{ | ||
static Checker() | ||
{ | ||
EditorApplication.delayCall += DoCheckForUpdate; | ||
} | ||
|
||
public static bool OutOfDate | ||
{ | ||
get => SessionState.GetBool("com.anatawa12.avatar-optimizer.out-of-date", false); | ||
private set => SessionState.SetBool("com.anatawa12.avatar-optimizer.out-of-date", value); | ||
} | ||
|
||
public static string LatestVersionName | ||
{ | ||
get => SessionState.GetString("com.anatawa12.avatar-optimizer.latest", ""); | ||
private set => SessionState.SetString("com.anatawa12.avatar-optimizer.latest", value); | ||
} | ||
|
||
public static string CurrentVersionName | ||
{ | ||
get => SessionState.GetString("com.anatawa12.avatar-optimizer.current", ""); | ||
private set => SessionState.SetString("com.anatawa12.avatar-optimizer.current", value); | ||
} | ||
|
||
public static bool IsBeta => CurrentVersionName.Contains("-"); | ||
|
||
static async void DoCheckForUpdate() | ||
{ | ||
if (!MenuItems.CheckForUpdateEnabled) | ||
{ | ||
// if disabled, do nothing | ||
OutOfDate = false; | ||
return; | ||
} | ||
|
||
if (!(GetCurrentVersion() is Version currentVersion)) | ||
{ | ||
Debug.LogError("Avatar Optimizer CheckForUpdate: Failed to get current version"); | ||
return; | ||
} | ||
|
||
CurrentVersionName = currentVersion.ToString(); | ||
|
||
var isBeta = currentVersion.IsPrerelease || MenuItems.ForceBetaChannel; | ||
if (!UnityVersion.TryParse(Application.unityVersion, out var unityVersion)) | ||
{ | ||
Debug.LogError("Avatar Optimizer CheckForUpdate: Failed to get unity version"); | ||
return; | ||
} | ||
|
||
var ctx = new CheckForUpdateContext(isBeta, currentVersion, unityVersion); | ||
|
||
if (await ctx.GetLatestVersion() is Version latestVersion) | ||
{ | ||
// there is known latest version | ||
if (currentVersion < latestVersion) | ||
{ | ||
OutOfDate = true; | ||
LatestVersionName = latestVersion.ToString(); | ||
|
||
Debug.Log("AAO CheckForUpdate: Out of date detected! " + | ||
$"current version: {currentVersion}, latest version: {latestVersion}"); | ||
} | ||
else | ||
{ | ||
OutOfDate = false; | ||
} | ||
} | ||
else | ||
{ | ||
OutOfDate = false; | ||
} | ||
} | ||
|
||
static Version? GetCurrentVersion() | ||
{ | ||
try | ||
{ | ||
var packageJson = | ||
JsonUtility.FromJson<PackageJson>( | ||
File.ReadAllText("Packages/com.anatawa12.avatar-optimizer/package.json")); | ||
if (packageJson.version == null) return null; | ||
if (!Version.TryParse(packageJson.version, out var version)) return null; | ||
return version; | ||
} | ||
catch (Exception e) | ||
{ | ||
Debug.LogException(e); | ||
return null; | ||
} | ||
} | ||
|
||
[Serializable] | ||
class PackageJson | ||
{ | ||
public string version; | ||
} | ||
} | ||
} |
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.