mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-29 18:34:33 +00:00
Merge branch 'main' into '3dSkinRenderer'
This commit is contained in:
@@ -1,140 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Drawing;
|
||||
using Newtonsoft.Json;
|
||||
using PckStudio.API.PCKCenter.model;
|
||||
|
||||
namespace PckStudio.API.PCKCenter
|
||||
{
|
||||
public class PCKCollections
|
||||
{
|
||||
WebClient client = new WebClient();
|
||||
public string CurrentPackDl = "";
|
||||
string cache = Program.AppDataCache + "/packs";
|
||||
public PCKCenterJSON CenterPacks;
|
||||
public LocalActions LocalAction = new LocalActions();
|
||||
|
||||
public string[] GetCategories() => GetCategories(false);
|
||||
|
||||
public string[] GetCategories(bool isVita)
|
||||
{
|
||||
try
|
||||
{
|
||||
return DownloadAndDeserializeJson<string[]>
|
||||
($"{Program.BaseAPIUrl}/center/packs/{(isVita ? "VitaCategiories.json" : "Categiories.json")}", client);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
public PCKCenterJSON GetPackDescs(string category, bool isVita)
|
||||
{
|
||||
string cat;
|
||||
try
|
||||
{
|
||||
cat = client.DownloadString($"{Program.BaseAPIUrl}/center/packs/{(isVita ? "vita" : "normal")}/{category}.json");
|
||||
}
|
||||
catch
|
||||
{
|
||||
cat = client.DownloadString($"{Program.BackUpAPIUrl}/center/packs/{(isVita ? "vita" : "normal")}/{category}.json");
|
||||
}
|
||||
PCKCenterJSON Data = JsonConvert.DeserializeObject<PCKCenterJSON>(cat);
|
||||
return Data;
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
public string[] GetPackDescription(string category, bool isVita)
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
string cat;
|
||||
try
|
||||
{
|
||||
cat = client.DownloadString($"{Program.BaseAPIUrl}/studio/PCK/api/pcks{(isVita ? "/Vita" : "")}/{category}.desc");
|
||||
}
|
||||
catch
|
||||
{
|
||||
cat = client.DownloadString($"{Program.BackUpAPIUrl}/studio/PCK/api/pcks{(isVita ? "/Vita" : "")}/{category}.desc");
|
||||
}
|
||||
return cat.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
public Image GetPackImage(int packId, bool isVita)
|
||||
{
|
||||
byte[] data;
|
||||
try
|
||||
{
|
||||
data = client.DownloadData($"{Program.BaseAPIUrl}/center/packs/{(isVita ? "vita" : "normal")}/images/{packId}.png");
|
||||
}
|
||||
catch
|
||||
{
|
||||
data = client.DownloadData($"{Program.BackUpAPIUrl}/center/packs/{(isVita ? "vita" : "normal")}/images/{packId}.png");
|
||||
}
|
||||
Image image;
|
||||
using (MemoryStream fs = new MemoryStream(data))
|
||||
{
|
||||
image = Image.FromStream(fs);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
public bool TryDownloadPack(string category, int packId, bool isVita)
|
||||
{
|
||||
try
|
||||
{
|
||||
Image packImage = GetPackImage(packId, isVita);
|
||||
packImage.Save($"{cache}/{(isVita ? "vita" : "normal")}/images/" + packId + ".png");
|
||||
packImage.Dispose();
|
||||
|
||||
Directory.CreateDirectory(cache + "/normal/");
|
||||
Directory.CreateDirectory(cache + "/normal/images");
|
||||
Directory.CreateDirectory(cache + "/normal/pcks");
|
||||
Directory.CreateDirectory(cache + "/vita/");
|
||||
Directory.CreateDirectory(cache + "/vita/images");
|
||||
Directory.CreateDirectory(cache + "/vita/pcks");
|
||||
PCKCenterJSON Local = LocalAction.GetLocalJSON(category, isVita);
|
||||
client.DownloadFile($"{Program.BaseAPIUrl}/center/packs/{(isVita ? "vita" : "normal")}/pcks/{packId}.pck", $"{cache}/vita/pcks/{packId}.pck");
|
||||
|
||||
Local = LocalAction.AddPack(Local, CenterPacks.Data[packId.ToString()], packId);
|
||||
LocalAction.SaveLocalJSON(Local, category, isVita);
|
||||
LocalAction.SaveLocalCategories(isVita);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
T DownloadAndDeserializeJson<T>(string address, WebClient client = null)
|
||||
{
|
||||
WebClient wc = client ?? new WebClient();
|
||||
string jsonData = wc.DownloadString(address);
|
||||
return JsonConvert.DeserializeObject<T>(jsonData);
|
||||
}
|
||||
|
||||
PCKCenterJSON DownloadCategoryJson(string categorie, bool isVita, WebClient client = null)
|
||||
{
|
||||
return DownloadAndDeserializeJson<PCKCenterJSON>
|
||||
($"{Program.BaseAPIUrl}/center/packs/{(isVita ? "vita" :"normal")}/{categorie}.json", client);
|
||||
}
|
||||
|
||||
public void TryTestPackInfo(bool isVita)
|
||||
{
|
||||
try
|
||||
{
|
||||
WebClient client = new WebClient();
|
||||
string categoryJSON = client.DownloadString(Program.BaseAPIUrl + "/center/packs/Categiories.json");
|
||||
string[] categories = JsonConvert.DeserializeObject<string[]>(categoryJSON);
|
||||
PCKCenterJSON result = DownloadCategoryJson(categories[2], false, client);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using Newtonsoft.Json;
|
||||
using PckStudio.API.PCKCenter.model;
|
||||
|
||||
namespace PckStudio.API.PCKCenter
|
||||
{
|
||||
public class PCKCollectionsLocal
|
||||
{
|
||||
static string cache = Program.AppDataCache + "/packs/";
|
||||
|
||||
public PCKCenterJSON CenterPacks;
|
||||
public LocalActions LocalAction = new LocalActions();
|
||||
|
||||
public string[] GetLocalCategories(bool isVita)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<string> Cats = new List<string>();
|
||||
foreach (string file in Directory.GetFiles(cache + (isVita ? "vita/" : "normal/")))
|
||||
{
|
||||
if (Path.GetExtension(file) == ".json")
|
||||
Cats.Add(Path.GetFileNameWithoutExtension(file));
|
||||
}
|
||||
return Cats.ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
return new string[] { };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public PCKCenterJSON GetLocalPackDescs(string Category, bool IsVita)
|
||||
{
|
||||
string filepath = cache + (IsVita ? "vita/" : "normal/") + Category + ".json";
|
||||
if (!File.Exists(filepath))
|
||||
{
|
||||
return new PCKCenterJSON();
|
||||
}
|
||||
string StringData = File.ReadAllText(filepath);
|
||||
return JsonConvert.DeserializeObject<PCKCenterJSON>(StringData);
|
||||
}
|
||||
|
||||
|
||||
public string GetLocalPackName(string Category, bool IsVita)
|
||||
{
|
||||
return GetLocalPackData(Category, IsVita)[0];
|
||||
}
|
||||
|
||||
|
||||
public string[] GetLocalPackData(string Category, bool IsVita)
|
||||
{
|
||||
string cat = "";
|
||||
string filepath = cache + (IsVita ? "descs/Vita/" : "descs/") + Category + ".desc";
|
||||
if (File.Exists(filepath))
|
||||
{
|
||||
cat = File.ReadAllText(filepath);
|
||||
}
|
||||
return cat.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
|
||||
public Image GetLocalPackImage(int packID, bool IsVita)
|
||||
{
|
||||
string filepath = cache + (IsVita ? "vita/images/" : "normal/images/") + packID + ".png";
|
||||
if (File.Exists(filepath))
|
||||
{
|
||||
return Image.FromFile(filepath);
|
||||
}
|
||||
return null; // TODO: add default Pack Image ?
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using PckStudio.API.PCKCenter.model;
|
||||
|
||||
namespace PckStudio.API.PCKCenter
|
||||
{
|
||||
public class LocalActions
|
||||
{
|
||||
string cache = Program.AppDataCache + "/packs/";
|
||||
public bool SaveLocalJSON(PCKCenterJSON JSONData, string category, bool isVita)
|
||||
{
|
||||
try
|
||||
{
|
||||
string outputString = JsonConvert.SerializeObject(JSONData, Formatting.Indented);
|
||||
File.WriteAllText(cache + (isVita ? "vita/" : "normal/") + category + ".json", outputString);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public PCKCenterJSON GetLocalJSON(string category, bool isVita)
|
||||
{
|
||||
try
|
||||
{
|
||||
string JSONData = File.ReadAllText(cache + (isVita ? "vita/" : "normal/") + category + ".json");
|
||||
return JsonConvert.DeserializeObject<PCKCenterJSON>(JSONData);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
PCKCenterJSON JSONData = new PCKCenterJSON();
|
||||
JSONData.Data = new Dictionary<string, EntryInfo>();
|
||||
return JSONData;
|
||||
}
|
||||
}
|
||||
public PCKCenterJSON AddPack(PCKCenterJSON JSONData, EntryInfo EInfo, int PackID)
|
||||
{
|
||||
JSONData.Data.Add(PackID.ToString(), EInfo);
|
||||
return JSONData;
|
||||
}
|
||||
public PCKCenterJSON Removepack(PCKCenterJSON JSONData, int PackID)
|
||||
{
|
||||
JSONData.Data.Remove(PackID.ToString());
|
||||
return JSONData;
|
||||
}
|
||||
|
||||
public bool SaveLocalCategories(bool isVita)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<string> Cats = new List<string>();
|
||||
string StringData = "";
|
||||
foreach(string file in Directory.GetFiles(cache + (isVita ? "vita/" : "normal/")))
|
||||
{
|
||||
if (Path.GetExtension(file) == ".json")
|
||||
Cats.Add(Path.GetFileNameWithoutExtension(file));
|
||||
}
|
||||
StringData = JsonConvert.SerializeObject(Cats.ToArray(), Formatting.Indented);
|
||||
File.WriteAllText(cache + (isVita ? "VitaCategiories.json" : "Categiories.json"), StringData);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PckStudio.API.PCKCenter.model
|
||||
{
|
||||
public class PCKCenterJSON
|
||||
{
|
||||
public Dictionary<string, EntryInfo> Data { get; set; }
|
||||
}
|
||||
|
||||
public class EntryInfo
|
||||
{
|
||||
public string Name;
|
||||
public string Author;
|
||||
public string Description;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ using PckStudio.Internal.Serializer;
|
||||
|
||||
namespace PckStudio.Extensions
|
||||
{
|
||||
internal static class PckFileDataExtensions
|
||||
internal static class PckAssetExtensions
|
||||
{
|
||||
private const string MipMap = "MipMapLevel";
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace PckStudio.Extensions
|
||||
}
|
||||
}
|
||||
|
||||
internal static T GetDeserializedData<T>(this PckAsset file, IPckDeserializer<T> deserializer)
|
||||
internal static T GetDeserializedData<T>(this PckAsset file, IPckAssetDeserializer<T> deserializer)
|
||||
{
|
||||
return deserializer.Deserialize(file);
|
||||
}
|
||||
@@ -133,7 +133,7 @@ namespace PckStudio.Extensions
|
||||
return formatReader.FromStream(ms);
|
||||
}
|
||||
|
||||
internal static void SetSerializedData<T>(this PckAsset file, T obj, IPckSerializer<T> serializer)
|
||||
internal static void SetSerializedData<T>(this PckAsset file, T obj, IPckAssetSerializer<T> serializer)
|
||||
{
|
||||
serializer.Serialize(obj, ref file);
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@ using OMI.Formats.Pck;
|
||||
|
||||
namespace PckStudio.Interfaces
|
||||
{
|
||||
internal interface IPckDeserializer<T>
|
||||
internal interface IPckAssetDeserializer<T>
|
||||
{
|
||||
public T Deserialize(PckAsset file);
|
||||
}
|
||||
@@ -7,7 +7,7 @@ using OMI.Formats.Pck;
|
||||
|
||||
namespace PckStudio.Interfaces
|
||||
{
|
||||
internal interface IPckSerializer<T>
|
||||
internal interface IPckAssetSerializer<T>
|
||||
{
|
||||
public void Serialize(T obj, ref PckAsset file);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ using PckStudio.Interfaces;
|
||||
|
||||
namespace PckStudio.Internal.Deserializer
|
||||
{
|
||||
internal sealed class AnimationDeserializer : IPckDeserializer<Animation>
|
||||
internal sealed class AnimationDeserializer : IPckAssetDeserializer<Animation>
|
||||
{
|
||||
public static readonly AnimationDeserializer DefaultDeserializer = new AnimationDeserializer();
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ using PckStudio.IO.TGA;
|
||||
|
||||
namespace PckStudio.Internal.Deserializer
|
||||
{
|
||||
internal sealed class ImageDeserializer : IPckDeserializer<Image>
|
||||
internal sealed class ImageDeserializer : IPckAssetDeserializer<Image>
|
||||
{
|
||||
public static readonly ImageDeserializer DefaultDeserializer = new ImageDeserializer();
|
||||
private static Image EmptyImage = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
|
||||
|
||||
@@ -13,7 +13,7 @@ using PckStudio.Interfaces;
|
||||
|
||||
namespace PckStudio.Internal.Serializer
|
||||
{
|
||||
internal sealed class AnimationSerializer : IPckSerializer<Animation>
|
||||
internal sealed class AnimationSerializer : IPckAssetSerializer<Animation>
|
||||
{
|
||||
public static readonly AnimationSerializer DefaultSerializer = new AnimationSerializer();
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ using PckStudio.IO.TGA;
|
||||
|
||||
namespace PckStudio.Internal.Serializer
|
||||
{
|
||||
internal sealed class ImageSerializer : IPckSerializer<Image>
|
||||
internal sealed class ImageSerializer : IPckAssetSerializer<Image>
|
||||
{
|
||||
public static readonly ImageSerializer DefaultSerializer = new ImageSerializer();
|
||||
|
||||
|
||||
@@ -137,8 +137,8 @@
|
||||
<Compile Include="Classes\IO\TGA\TGADeserializer.cs" />
|
||||
<Compile Include="Classes\IO\TGA\TGASerializer.cs" />
|
||||
<Compile Include="Extensions\LocFileExtensions.cs" />
|
||||
<Compile Include="Extensions\PckAssetExtensions.cs" />
|
||||
<Compile Include="Extensions\CursorExtensions.cs" />
|
||||
<Compile Include="Extensions\PckFileDataExtensions.cs" />
|
||||
<Compile Include="Extensions\SkinBOXExtensions.cs" />
|
||||
<Compile Include="Extensions\SkinExtensions.cs" />
|
||||
<Compile Include="Extensions\System.Numerics.cs" />
|
||||
@@ -149,8 +149,8 @@
|
||||
<Compile Include="Internal\Deserializer\ImageDeserializer.cs" />
|
||||
<Compile Include="Internal\Serializer\AnimationSerializer.cs" />
|
||||
<Compile Include="Internal\Deserializer\AnimationDeserializer.cs" />
|
||||
<Compile Include="Interfaces\IPckDeserializer.cs" />
|
||||
<Compile Include="Interfaces\IPckSerializer.cs" />
|
||||
<Compile Include="Interfaces\IPckAssetDeserializer.cs" />
|
||||
<Compile Include="Interfaces\IPckAssetSerializer.cs" />
|
||||
<Compile Include="Internal\Json\Entities.cs" />
|
||||
<Compile Include="Internal\Json\EntityInfo.cs" />
|
||||
<Compile Include="Internal\ResourceCategory.cs" />
|
||||
@@ -237,10 +237,6 @@
|
||||
<Compile Include="Forms\Editor\TextureAtlasEditor.Designer.cs">
|
||||
<DependentUpon>TextureAtlasEditor.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Classes\API\PCKCenter\model\PCKCenterJSON.cs" />
|
||||
<Compile Include="Classes\API\PCKCenter\PCKCollections.cs" />
|
||||
<Compile Include="Classes\API\PCKCenter\PCKCollectionsLocal.cs" />
|
||||
<Compile Include="Classes\API\PCKCenter\SaveLocalJSON.cs" />
|
||||
<Compile Include="Extensions\BlendMode.cs" />
|
||||
<Compile Include="Extensions\ColorExtensions.cs" />
|
||||
<Compile Include="Extensions\EnumerableExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user