first commit

This commit is contained in:
Kirill Chikalin
2024-11-16 13:20:07 +03:00
commit a3072a3693
538 changed files with 108153 additions and 0 deletions

View File

@@ -0,0 +1,128 @@
using AssetStoreTools.Utility.Json;
using System.IO;
using System.Text;
using UnityEngine;
namespace AssetStoreTools.Uploader.Utility
{
internal static class AssetStoreCache
{
public const string TempCachePath = "Temp/AssetStoreToolsCache";
public const string PersistentCachePath = "Library/AssetStoreToolsCache";
private const string PackageDataFile = "PackageMetadata.json";
private const string CategoryDataFile = "Categories.json";
private static void CreateFileInTempCache(string fileName, object content, bool overwrite)
{
CreateCacheFile(TempCachePath, fileName, content, overwrite);
}
private static void CreateFileInPersistentCache(string fileName, object content, bool overwrite)
{
CreateCacheFile(PersistentCachePath, fileName, content, overwrite);
}
private static void CreateCacheFile(string rootPath, string fileName, object content, bool overwrite)
{
if (!Directory.Exists(rootPath))
Directory.CreateDirectory(rootPath);
var fullPath = Path.Combine(rootPath, fileName);
if(File.Exists(fullPath))
{
if (overwrite)
File.Delete(fullPath);
else
return;
}
switch (content)
{
case byte[] bytes:
File.WriteAllBytes(fullPath, bytes);
break;
default:
File.WriteAllText(fullPath, content.ToString());
break;
}
}
public static void ClearTempCache()
{
if (!File.Exists(Path.Combine(TempCachePath, PackageDataFile)))
return;
// Cache consists of package data and package texture thumbnails. We don't clear
// texture thumbnails here since they are less likely to change. They are still
// deleted and redownloaded every project restart (because of being stored in the 'Temp' folder)
File.Delete(Path.Combine(TempCachePath, PackageDataFile));
}
public static void CacheCategories(JsonValue data)
{
CreateFileInTempCache(CategoryDataFile, data, true);
}
public static bool GetCachedCategories(out JsonValue data)
{
data = new JsonValue();
var path = Path.Combine(TempCachePath, CategoryDataFile);
if (!File.Exists(path))
return false;
data = JSONParser.SimpleParse(File.ReadAllText(path, Encoding.UTF8));
return true;
}
public static void CachePackageMetadata(JsonValue data)
{
CreateFileInTempCache(PackageDataFile, data.ToString(), true);
}
public static bool GetCachedPackageMetadata(out JsonValue data)
{
data = new JsonValue();
var path = Path.Combine(TempCachePath, PackageDataFile);
if (!File.Exists(path))
return false;
data = JSONParser.SimpleParse(File.ReadAllText(path, Encoding.UTF8));
return true;
}
public static void CacheTexture(string packageId, Texture2D texture)
{
CreateFileInTempCache($"{packageId}.png", texture.EncodeToPNG(), true);
}
public static bool GetCachedTexture(string packageId, out Texture2D texture)
{
texture = new Texture2D(1, 1);
var path = Path.Combine(TempCachePath, $"{packageId}.png");
if (!File.Exists(path))
return false;
texture.LoadImage(File.ReadAllBytes(path));
return true;
}
public static void CacheUploadSelections(string packageId, JsonValue json)
{
var fileName = $"{packageId}-uploadselection.asset";
CreateFileInPersistentCache(fileName, json.ToString(), true);
}
public static bool GetCachedUploadSelections(string packageId, out JsonValue json)
{
json = new JsonValue();
var path = Path.Combine(PersistentCachePath, $"{packageId}-uploadselection.asset");
if (!File.Exists(path))
return false;
json = JSONParser.SimpleParse(File.ReadAllText(path, Encoding.UTF8));
return true;
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 2e5fee0cad7655f458d9b600f4ae6d02
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 115
packageName: Asset Store Publishing Tools
packageVersion: 11.4.3
assetPath: Packages/com.unity.asset-store-tools/Editor/Uploader/Scripts/Utility/AssetStoreCache.cs
uploadId: 681981

View File

@@ -0,0 +1,93 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using AssetStoreTools.Uploader.Data;
using AssetStoreTools.Utility;
using AssetStoreTools.Utility.Json;
namespace AssetStoreTools.Uploader.Utility
{
internal class PackageFetcher
{
public abstract class PackageFetcherResult
{
public bool Success;
public bool SilentFail;
public ASError Error;
public JsonValue Json;
}
public class PackageFetcherResultSingle : PackageFetcherResult
{
public PackageData Package;
}
public class PackageFetcherResultCollection : PackageFetcherResult
{
public ICollection<PackageData> Packages;
}
public async Task<PackageFetcherResultCollection> Fetch(bool useCached)
{
var result = await AssetStoreAPI.GetFullPackageDataAsync(useCached);
if (!result.Success)
return new PackageFetcherResultCollection() { Success = false, Error = result.Error, SilentFail = result.SilentFail };
if (result.Response.Equals(default(JsonValue)))
{
ASDebug.Log("No packages fetched");
return new PackageFetcherResultCollection() { Success = true, Packages = null, Json = result.Response };
}
var packages = ParsePackages(result.Response);
return new PackageFetcherResultCollection() { Success = true, Packages = packages, Json = result.Response };
}
public async Task<PackageFetcherResultSingle> FetchRefreshedPackage(string packageId)
{
var result = await AssetStoreAPI.GetRefreshedPackageData(packageId);
if (!result.Success)
{
ASDebug.LogError(result.Error.Message);
return new PackageFetcherResultSingle() { Success = false, Error = result.Error, SilentFail = result.SilentFail };
}
var package = ParseRefreshedPackage(packageId, result.Response);
return new PackageFetcherResultSingle() { Success = true, Package = package };
}
private ICollection<PackageData> ParsePackages(JsonValue json)
{
List<PackageData> packageList = new List<PackageData>();
var packageDict = json["packages"].AsDict(true);
ASDebug.Log($"All packages\n{json["packages"]}");
// Each package has an identifier and a bunch of data (current version id, name, etc.)
foreach (var p in packageDict)
{
var packageId = p.Key;
var package = ParseRefreshedPackage(packageId, p.Value);
packageList.Add(package);
}
return packageList;
}
private PackageData ParseRefreshedPackage(string packageId, JsonValue json)
{
var packageName = json["name"].AsString(true);
var versionId = json["id"].AsString(true);
var statusName = json["status"].AsString(true);
var isCompleteProject = json["is_complete_project"].AsBool(true);
var categoryName = json["extra_info"].Get("category_info").Get("name").AsString(true);
var lastUploadedPath = json["project_path"].IsString() ? json["project_path"].AsString() : string.Empty;
var lastUploadedGuid = json["root_guid"].IsString() ? json["root_guid"].AsString() : string.Empty;
var lastDate = json["extra_info"].Get("modified").AsString(true);
var lastSize = json["extra_info"].Get("size").AsString(true);
var package = new PackageData(packageId, packageName, versionId, statusName, categoryName, isCompleteProject, lastUploadedPath, lastUploadedGuid, lastDate, lastSize);
ASDebug.Log(package);
return package;
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 24e1d75365cc42a09e5c5daec071813e
timeCreated: 1658918833
AssetOrigin:
serializedVersion: 1
productId: 115
packageName: Asset Store Publishing Tools
packageVersion: 11.4.3
assetPath: Packages/com.unity.asset-store-tools/Editor/Uploader/Scripts/Utility/PackageFetcher.cs
uploadId: 681981

View File

@@ -0,0 +1,31 @@
using AssetStoreTools.Uploader.Data;
using AssetStoreTools.Uploader.UIElements;
using System.Collections.Generic;
namespace AssetStoreTools.Uploader.Utility
{
internal static class PackageViewStorer
{
private static readonly Dictionary<string, PackageView> SavedPackages = new Dictionary<string, PackageView>();
public static PackageView GetPackage(PackageData packageData)
{
string versionId = packageData.VersionId;
if (SavedPackages.ContainsKey(versionId))
{
var savedPackage = SavedPackages[versionId];
savedPackage.UpdateDataValues(packageData);
return savedPackage;
}
var package = new PackageView(packageData);
SavedPackages.Add(package.VersionId, package);
return package;
}
public static void Reset()
{
SavedPackages.Clear();
}
}
}

View File

@@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 582639e8ed53f37499d12efcb4cde2c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
AssetOrigin:
serializedVersion: 1
productId: 115
packageName: Asset Store Publishing Tools
packageVersion: 11.4.3
assetPath: Packages/com.unity.asset-store-tools/Editor/Uploader/Scripts/Utility/PackageViewStorer.cs
uploadId: 681981