diff --git a/MinecraftUSkinEditor/Classes/API/PCKCenter/SaveLocalJSON.cs b/MinecraftUSkinEditor/Classes/API/PCKCenter/SaveLocalJSON.cs new file mode 100644 index 00000000..6f20304f --- /dev/null +++ b/MinecraftUSkinEditor/Classes/API/PCKCenter/SaveLocalJSON.cs @@ -0,0 +1,111 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using API.PCKCenter.model; + +namespace API.PCKCenter +{ + public class LocalActions + { + string cache = PckStudio.Program.Appdata + "cache/packs/"; + public bool SaveLocalJSON(PCKCenterJSON JSONData, string category, bool isVita) + { + try + { + string outputString = JsonConvert.SerializeObject(JSONData, Formatting.Indented); + + switch (isVita) + { + case false: + File.WriteAllText(cache + "normal/" + category + ".json", outputString); + break; + case true: + File.WriteAllText(cache + "vita/" + category + ".json", outputString); + break; + } + + return true; + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return false; + } + } + + public PCKCenterJSON GetLocalJSON(string category, bool isVita) + { + try + { + string JSONData = ""; + switch (isVita) + { + case false: + JSONData = File.ReadAllText(cache + "normal/" + category + ".json"); + break; + case true: + JSONData = File.ReadAllText(cache + "vita/" + category + ".json"); + break; + } + return JsonConvert.DeserializeObject(JSONData); + } + catch(Exception ex) + { + Console.WriteLine(ex.Message); + PCKCenterJSON JSONData = new PCKCenterJSON(); + JSONData.Data = new Dictionary(); + 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 Cats = new List(); + string StringData = ""; + switch (isVita) + { + case false: + foreach(string file in Directory.GetFiles(cache + "normal/")) + { + if (Path.GetExtension(file) == ".json") + Cats.Add(Path.GetFileNameWithoutExtension(file)); + } + StringData = JsonConvert.SerializeObject(Cats.ToArray(), Formatting.Indented); + File.WriteAllText(cache + "Categiories.json", StringData); + break; + case true: + foreach (string file in Directory.GetFiles(cache + "vita/")) + { + if (Path.GetExtension(file) == ".json") + Cats.Add(Path.GetFileNameWithoutExtension(file)); + } + StringData = JsonConvert.SerializeObject(Cats.ToArray(), Formatting.Indented); + File.WriteAllText(cache + "VitaCategiories.json", StringData); + break; + } + return true; + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return false; + } + } + } +} diff --git a/MinecraftUSkinEditor/Classes/API/PCKCenter/model/PCKCenterJSON.cs b/MinecraftUSkinEditor/Classes/API/PCKCenter/model/PCKCenterJSON.cs new file mode 100644 index 00000000..1305567a --- /dev/null +++ b/MinecraftUSkinEditor/Classes/API/PCKCenter/model/PCKCenterJSON.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace API.PCKCenter.model +{ + public class PCKCenterJSON + { + public Dictionary Data { get; set; } + } + + public class EntryInfo + { + public string Name; + public string Author; + public string Description; + } +} diff --git a/MinecraftUSkinEditor/Classes/IO/PCKCollectionsLocal.cs b/MinecraftUSkinEditor/Classes/IO/PCKCollectionsLocal.cs index 9db070ad..9b6f6c06 100644 --- a/MinecraftUSkinEditor/Classes/IO/PCKCollectionsLocal.cs +++ b/MinecraftUSkinEditor/Classes/IO/PCKCollectionsLocal.cs @@ -5,40 +5,74 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Drawing; +using Newtonsoft.Json; +using API.PCKCenter.model; +using API.PCKCenter; namespace PckStudio.Classes.IO { public class PCKCollectionsLocal { string cache = Program.Appdata + "cache/packs/"; - public string[] GetLocalCategories() + + public PCKCenterJSON CenterPacks; + public LocalActions LocalAction = new LocalActions(); + + public string[] GetLocalCategories(bool isVita) { - string cat = ""; - if (File.Exists(cache + "PCKCategories.txt")) - cat = File.ReadAllText(cache + "PCKCategories.txt"); - return cat.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); + try + { + List Cats = new List(); + switch (isVita) + { + case false: + foreach (string file in Directory.GetFiles(cache + "normal/")) + { + if (Path.GetExtension(file) == ".json") + Cats.Add(Path.GetFileNameWithoutExtension(file)); + } + break; + case true: + foreach (string file in Directory.GetFiles(cache + "vita/")) + { + if (Path.GetExtension(file) == ".json") + Cats.Add(Path.GetFileNameWithoutExtension(file)); + } + break; + } + return Cats.ToArray(); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + return new string[] { }; + } } - public string[] GetLocalPackDescs(string Category, bool IsVita) + public PCKCenterJSON GetLocalPackDescs(string Category, bool IsVita) { - string cat = ""; + string StringData = ""; try { switch (IsVita) { case (true): - cat = File.ReadAllText(cache + "Category/VitaCategory" + Category + ".txt"); + StringData = File.ReadAllText(cache + "vita/ " + Category + ".json"); break; case (false): - cat = File.ReadAllText(cache + "Category/Category" + Category + ".txt"); + StringData = File.ReadAllText(cache + "normal/" + Category + ".json"); break; } } - catch + catch (Exception e) { + Console.WriteLine(e.Message); + return new PCKCenterJSON(); } - return cat.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); + + PCKCenterJSON Data = JsonConvert.DeserializeObject(StringData); + return Data; } @@ -87,7 +121,7 @@ namespace PckStudio.Classes.IO } - public Image GetLocalPackImage(string Category, bool IsVita) + public Image GetLocalPackImage(int packID, bool IsVita) { Image image = null; try @@ -95,10 +129,10 @@ namespace PckStudio.Classes.IO switch (IsVita) { case (true): - image = Image.FromFile(cache + "images/Vita/" + Category + ".png"); + image = Image.FromFile(cache + "vita/images/" + packID + ".png"); break; case (false): - image = Image.FromFile(cache + "images/" + Category + ".png"); + image = Image.FromFile(cache + "normal/images/" + packID + ".png"); break; } } diff --git a/MinecraftUSkinEditor/Classes/Networking/Network.cs b/MinecraftUSkinEditor/Classes/Networking/Network.cs index d04a46c8..fc6541a0 100644 --- a/MinecraftUSkinEditor/Classes/Networking/Network.cs +++ b/MinecraftUSkinEditor/Classes/Networking/Network.cs @@ -10,10 +10,10 @@ namespace PckStudio.Classes public static bool Beta = true; public static bool Portable = false; public static bool NeedsUpdate = false; - public static string MainURL = "http://pckstudio.xyz/"; + public static string MainURL = "http://api.pckstudio.xyz/api/pck"; public static string BackURL = "http://phoenixarc.ddns.net/"; - static string UpdateURL = "studio/PCK/api/updatePCKStudio.txt"; - static string BetaUpdateURL = "studio/PCK/api/updatePCKStudioB.txt"; + static string UpdateURL = "/update/Version"; + static string BetaUpdateURL = "/update/VersionBeta"; public static void CheckUpdate() { diff --git a/MinecraftUSkinEditor/Classes/Networking/PCKCollections.cs b/MinecraftUSkinEditor/Classes/Networking/PCKCollections.cs index 6c17f802..75e48849 100644 --- a/MinecraftUSkinEditor/Classes/Networking/PCKCollections.cs +++ b/MinecraftUSkinEditor/Classes/Networking/PCKCollections.cs @@ -8,6 +8,9 @@ using System.Threading.Tasks; using System.Drawing.Imaging; using System.Drawing.Design; using System.Drawing; +using Newtonsoft.Json; +using API.PCKCenter.model; +using API.PCKCenter; namespace PckStudio.Classes.Networking { @@ -16,35 +19,34 @@ namespace PckStudio.Classes.Networking WebClient client = new WebClient(); public string CurrentPackDl = ""; string cache = Program.Appdata + "cache/packs/"; + public PCKCenterJSON CenterPacks; + public LocalActions LocalAction = new LocalActions(); public string[] GetCategories() { string cat = ""; try { - cat = client.DownloadString(PckStudio.Classes.Network.MainURL + "/studio/PCK/api/PCKCategories.txt"); - client.DownloadFile(PckStudio.Classes.Network.MainURL + "/studio/PCK/api/PCKCategories.txt", cache + "PCKCategories.txt"); + cat = client.DownloadString(Program.baseurl + "/center/packs/Categiories.json"); } catch { - cat = client.DownloadString(PckStudio.Classes.Network.BackURL + "/studio/PCK/api/PCKCategories.txt"); - client.DownloadFile(PckStudio.Classes.Network.BackURL + "/studio/PCK/api/PCKCategories.txt", cache + "PCKCategories.txt"); + cat = client.DownloadString(Program.baseurl + "/center/packs/VitaCategiories.json"); } - return cat.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); + return JsonConvert.DeserializeObject(cat); } - public string[] GetPackDescs(string Category, bool IsVita) + public PCKCenterJSON GetPackDescs(string Category, bool IsVita) { string cat = ""; try { - Console.WriteLine(PckStudio.Classes.Network.MainURL + "/studio/PCK/api/Category/Category" + Category + ".txt"); switch (IsVita) { case (true): - cat = client.DownloadString(PckStudio.Classes.Network.MainURL + "/studio/PCK/api/Category/VitaCategory" + Category + ".txt"); + cat = client.DownloadString(Program.baseurl + "/center/packs/vita/" + Category + ".json"); break; case (false): - cat = client.DownloadString(PckStudio.Classes.Network.MainURL + "/studio/PCK/api/Category/Category" + Category + ".txt"); + cat = client.DownloadString(Program.baseurl + "/center/packs/normal/" + Category + ".json"); break; } } @@ -53,48 +55,17 @@ namespace PckStudio.Classes.Networking switch (IsVita) { case (true): - cat = client.DownloadString(PckStudio.Classes.Network.BackURL + "/studio/PCK/api/Category/VitaCategory" + Category + ".txt"); + cat = client.DownloadString(Program.backurl + "/center/packs/vita/" + Category + ".json"); break; case (false): - cat = client.DownloadString(PckStudio.Classes.Network.BackURL + "/studio/PCK/api/Category/Category" + Category + ".txt"); + cat = client.DownloadString(Program.backurl + "/center/packs/normal/" + Category + ".json"); break; } } - return cat.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); - } - public string GetPackName(string Category, bool IsVita) - { - string cat = ""; - try - { - Console.WriteLine(PckStudio.Classes.Network.MainURL + "/studio/PCK/api/pcks/" + Category + ".desc"); - switch (IsVita) - { - case (true): - cat = client.DownloadString(PckStudio.Classes.Network.MainURL + "/studio/PCK/api/pcks/Vita/" + Category + ".desc"); - break; - case (false): - cat = client.DownloadString(PckStudio.Classes.Network.MainURL + "/studio/PCK/api/pcks/" + Category + ".desc"); - break; - } - } - catch(Exception err) - { - switch (IsVita) - { - case (true): - cat = client.DownloadString(PckStudio.Classes.Network.BackURL + "/studio/PCK/api/pcks/Vita/" + Category + ".desc"); - break; - case (false): - cat = client.DownloadString(PckStudio.Classes.Network.BackURL + "/studio/PCK/api/pcks/" + Category + ".desc"); - break; - } - } - string[] data = cat.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); - return data[0]; + PCKCenterJSON Data = JsonConvert.DeserializeObject(cat); + return Data; } - public string[] GetPackData(string Category, bool IsVita) { string cat = ""; @@ -125,7 +96,7 @@ namespace PckStudio.Classes.Networking return cat.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries); } - public Image GetPackImage(string Category, bool IsVita) + public Image GetPackImage(int packID, bool IsVita) { byte[] cat = new byte[] { }; try @@ -133,10 +104,10 @@ namespace PckStudio.Classes.Networking switch (IsVita) { case (true): - cat = client.DownloadData(PckStudio.Classes.Network.MainURL + "/studio/PCK/api/pcks/Vita/image/" + Category + ".png"); + cat = client.DownloadData(Program.baseurl + "/center/packs/vita/images/" + packID + ".png"); break; case (false): - cat = client.DownloadData(PckStudio.Classes.Network.MainURL + "/studio/PCK/api/pcks/image/" + Category + ".png"); + cat = client.DownloadData(Program.baseurl + "/center/packs/normal/images/" + packID + ".png"); break; } } @@ -145,10 +116,10 @@ namespace PckStudio.Classes.Networking switch (IsVita) { case (true): - cat = client.DownloadData(PckStudio.Classes.Network.BackURL + "/studio/PCK/api/pcks/Vita/image/" + Category + ".png"); + cat = client.DownloadData(Program.backurl + "/center/packs/vita/images/" + packID + ".png"); break; case (false): - cat = client.DownloadData(PckStudio.Classes.Network.BackURL + "/studio/PCK/api/pcks/image/" + Category + ".png"); + cat = client.DownloadData(Program.backurl + "/center/packs/normal/images/" + packID + ".png"); break; } } @@ -160,37 +131,35 @@ namespace PckStudio.Classes.Networking return image; } - public bool TryDownloadPack(string Category, bool IsVita, string PackCat) + public bool TryDownloadPack(int packID, bool IsVita, string Category) { try { - string[] desc = GetPackData(Category, IsVita); - Image image = GetPackImage(Category, IsVita); - string DescPath = cache; - Directory.CreateDirectory(cache + "descs/Vita/"); - Directory.CreateDirectory(cache + "images/Vita/"); - Directory.CreateDirectory(cache + "files/Vita/"); - Directory.CreateDirectory(cache + "Category/"); + Image image = GetPackImage(packID, IsVita); + string DescPath = cache; + 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); switch (IsVita) { - case (true): - DescPath = cache + "descs/Vita/" + Category + ".desc"; - image.Save(cache + "images/Vita/" + Category + ".png"); - File.WriteAllText(DescPath, desc[0] + "\n" + desc[1] + "\n" + desc[2]); - File.WriteAllText(cache + "Category/VitaCategory" + PackCat + ".txt", "\n"+ Category); - byte[] bytes = client.DownloadData(desc[3]); - File.WriteAllBytes(cache + "files/Vita/" + Category + ".pck", bytes); - break; case (false): - DescPath = cache + "descs/" + Category + ".desc"; - image.Save(cache + "images/" + Category + ".png"); - File.WriteAllText(DescPath, desc[0] + "\n" + desc[1] + "\n" + desc[2]); - File.WriteAllText(cache + "Category/Category" + PackCat + ".txt", "\n" + Category); - byte[] bytes2 = client.DownloadData(desc[3]); - File.WriteAllBytes(cache + "files/" + Category + ".pck", bytes2); + image.Save(cache + "normal/images/" + packID + ".png"); + client.DownloadFile(Program.baseurl + "/center/packs/normal/pcks/" + packID + ".pck", cache + "normal/pcks/" + packID + ".pck"); + break; + case (true): + image.Save(cache + "vita/images/" + packID + ".png"); + client.DownloadFile(Program.baseurl + "/center/packs/vita/pcks/" + packID + ".pck", cache + "vita/pcks/" + packID + ".pck"); break; } + Local = LocalAction.AddPack(Local, CenterPacks.Data[packID.ToString()], packID); + LocalAction.SaveLocalJSON(Local, Category, IsVita); + LocalAction.SaveLocalCategories(IsVita); + /**/ image.Dispose(); return true; } @@ -200,6 +169,28 @@ namespace PckStudio.Classes.Networking } } + public void TryTestPackInfo(bool IsVita) + { + try + { + WebClient wc = new WebClient(); + string CategoryJSON = wc.DownloadString(Program.baseurl + "/center/packs/Categiories.json"); + string[] Categories = JsonConvert.DeserializeObject(CategoryJSON); + PCKCenterJSON Result = pk1(Categories[2]); + Console.Write(""); // this is a breakpoint + } + catch + { + Console.Write(""); // this is a breakpoint + } + } + PCKCenterJSON pk1(string categorie) + { + WebClient wc = new WebClient(); + string DataJSON = wc.DownloadString(Program.baseurl + "/center/packs/normal/" + categorie + ".json"); + PCKCenterJSON Data = JsonConvert.DeserializeObject(DataJSON); + return Data; + } } } diff --git a/MinecraftUSkinEditor/Classes/Networking/Update.cs b/MinecraftUSkinEditor/Classes/Networking/Update.cs index ce99955f..bf318622 100644 --- a/MinecraftUSkinEditor/Classes/Networking/Update.cs +++ b/MinecraftUSkinEditor/Classes/Networking/Update.cs @@ -9,8 +9,8 @@ namespace PckStudio.Classes { class Update { - static string UpdateURL = "Download/setup/PCKStudio-Setup.msi"; - static string BetaUpdateURL = "Download/setup/beta/PCKStudioBeta-Setup.msi"; + static string UpdateURL = "/Update/Download/setup/PCKStudio-Setup.msi"; + static string BetaUpdateURL = "/Update/Download/setup/beta/PCKStudioBeta-Setup.msi"; public static void UpdateProgram(bool Beta) { diff --git a/MinecraftUSkinEditor/Classes/Program.cs b/MinecraftUSkinEditor/Classes/Program.cs index 06010a6b..f87a0007 100644 --- a/MinecraftUSkinEditor/Classes/Program.cs +++ b/MinecraftUSkinEditor/Classes/Program.cs @@ -13,7 +13,7 @@ namespace PckStudio static class Program { - public static string baseurl = "https://www.pckstudio.xyz/studio/PCK/api/"; + public static string baseurl = "http://api.pckstudio.xyz/api/pck"; public static string backurl = "https://raw.githubusercontent.com/PhoenixARC/pckstudio.tk/main/studio/PCK/api/"; public static string Appdata = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/PCK Studio/"; /// diff --git a/MinecraftUSkinEditor/Forms/Utilities/PckCenterBeta.cs b/MinecraftUSkinEditor/Forms/Utilities/PckCenterBeta.cs index 3cd77386..748678d1 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/PckCenterBeta.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/PckCenterBeta.cs @@ -14,6 +14,8 @@ using MetroFramework.Forms; using RichPresenceClient; using PckStudio.Classes.Networking; using PckStudio.Classes.IO; +using API.PCKCenter.model; +using API.PCKCenter; namespace PckStudio.Forms.Utilities { @@ -37,6 +39,7 @@ namespace PckStudio.Forms.Utilities public PCKCollections Collections = new PCKCollections(); public PCKCollectionsLocal LocalCollections = new PCKCollectionsLocal(); + LocalActions LActions = new LocalActions(); string cache = Program.Appdata + "cache/"; @@ -57,7 +60,7 @@ namespace PckStudio.Forms.Utilities } break; case 1: - string[] CatsL = LocalCollections.GetLocalCategories(); + string[] CatsL = LocalCollections.GetLocalCategories(VitaCheckBox2.Checked); foreach (string cat in CatsL) { CategoryComboBoxLocal.Items.Add(cat); @@ -78,53 +81,43 @@ namespace PckStudio.Forms.Utilities switch (metroTabControl1.SelectedIndex) { case 0: - switch (VitaCheckBox.Checked) + + PCKCenterJSON packs = Collections.GetPackDescs(CategoryComboBox.Text, VitaCheckBox.Checked); + Collections.CenterPacks = packs; + foreach (KeyValuePair entry in packs.Data) { - case true: - string[] packsVita = Collections.GetPackDescs(CategoryComboBox.Text, true); - foreach (string pack in packsVita) - { - if (!string.IsNullOrWhiteSpace(pack) && !string.IsNullOrEmpty(pack)) - OnlineTreeView.Nodes.Add(Collections.GetPackName(pack, true)); - } - break; - case false: - string[] packs = Collections.GetPackDescs(CategoryComboBox.Text, false); - foreach (string pack in packs) - { - if(!string.IsNullOrWhiteSpace(pack) && !string.IsNullOrEmpty(pack)) - OnlineTreeView.Nodes.Add(Collections.GetPackName(pack, false)); - } - break; + TreeNode tn = new TreeNode(entry.Value.Name); + tn.Tag = entry.Key; + OnlineTreeView.Nodes.Add(tn); } + break; case 1: - switch (VitaCheckBox2.Checked) + + PCKCenterJSON Localpacks = LocalCollections.GetLocalPackDescs(CategoryComboBoxLocal.Text, VitaCheckBox2.Checked); + LocalCollections.CenterPacks = Localpacks; + foreach (KeyValuePair entry in Localpacks.Data) { - case true: - string[] packsVita = LocalCollections.GetLocalPackDescs(CategoryComboBoxLocal.Text, true); - foreach (string pack in packsVita) - { - if (!string.IsNullOrWhiteSpace(pack) && !string.IsNullOrEmpty(pack)) - LocalTreeView.Nodes.Add(LocalCollections.GetLocalPackName(pack, true)); - } - break; - case false: - string[] packs = LocalCollections.GetLocalPackDescs(CategoryComboBoxLocal.Text, false); - foreach (string pack in packs) - { - if (!string.IsNullOrWhiteSpace(pack) && !string.IsNullOrEmpty(pack)) - LocalTreeView.Nodes.Add(LocalCollections.GetLocalPackName(pack, false)); - } - break; + TreeNode tn = new TreeNode(entry.Value.Name); + tn.Tag = entry.Key; + LocalTreeView.Nodes.Add(tn); } + break; } } - public bool IsPackLocal(string PackFile, bool IsVita) + public bool IsPackLocal(int PackID, bool IsVita) { - return File.Exists(cache + "packs/files/" + (IsVita ? "Vita/" : "") + PackFile + ".pck"); + switch (IsVita) + { + case true: + return File.Exists(cache + "packs/vita/pcks/" + PackID + ".pck"); + break; + case false: + return File.Exists(cache + "packs/normal/pcks/" + PackID + ".pck"); + break; + } } #endregion @@ -133,20 +126,19 @@ namespace PckStudio.Forms.Utilities { try { - string nam = "Pack Name: %n\nAuthor: %a\nDescription: %d"; - string[] packs = Collections.GetPackDescs(CategoryComboBox.Text, VitaCheckBox.Checked); - string[] Data = Collections.GetPackData(packs[OnlineTreeView.SelectedNode.Index], VitaCheckBox.Checked); + string nam = "Pack Name: %n\npack ID: %pid\nAuthor: %a\nDescription: %d"; + EntryInfo EI = Collections.CenterPacks.Data[OnlineTreeView.SelectedNode.Tag.ToString()]; - metroLabel1.Text = nam.Replace("%n", Data[0]).Replace("%a", Data[1]).Replace("%d", Data[2]); + metroLabel1.Text = nam.Replace("%n", EI.Name).Replace("%a", EI.Author).Replace("%d", EI.Description).Replace("%pid", OnlineTreeView.SelectedNode.Tag.ToString()); metroLabel1.AutoSize = false; metroLabel1.WrapToLine = true; - pictureBox1.Image = Collections.GetPackImage(packs[OnlineTreeView.SelectedNode.Index], VitaCheckBox.Checked); + pictureBox1.Image = Collections.GetPackImage(int.Parse(OnlineTreeView.SelectedNode.Tag.ToString()), VitaCheckBox.Checked); - if(!IsPackLocal(packs[OnlineTreeView.SelectedNode.Index], VitaCheckBox.Checked)) + if(!IsPackLocal(int.Parse(OnlineTreeView.SelectedNode.Tag.ToString()), VitaCheckBox.Checked)) DownloadButton.Visible = true; else - DownloadButton.Visible = false; + DownloadButton.Visible = false;/**/ } catch { @@ -170,9 +162,8 @@ namespace PckStudio.Forms.Utilities { try { - string[] packs = Collections.GetPackDescs(CategoryComboBox.Text, VitaCheckBox.Checked); - Collections.TryDownloadPack(packs[OnlineTreeView.SelectedNode.Index], VitaCheckBox.Checked, CategoryComboBox.Text); - MessageBox.Show("Download complete"); + Collections.TryDownloadPack(int.Parse(OnlineTreeView.SelectedNode.Tag.ToString()), VitaCheckBox.Checked, CategoryComboBox.Text); + MessageBox.Show("Download complete");/**/ } catch { @@ -189,15 +180,14 @@ namespace PckStudio.Forms.Utilities try { - string nam = "Pack Name: %n\nAuthor: %a\nDescription: %d"; - string[] packs = LocalCollections.GetLocalPackDescs(CategoryComboBoxLocal.Text, VitaCheckBox2.Checked); - string[] Data = LocalCollections.GetLocalPackData(packs[LocalTreeView.SelectedNode.Index], VitaCheckBox2.Checked); + string nam = "Pack Name: %n\npack ID: %pid\nAuthor: %a\nDescription: %d"; + EntryInfo EI = LocalCollections.CenterPacks.Data[LocalTreeView.SelectedNode.Tag.ToString()]; - metroLabel2.Text = nam.Replace("%n", Data[0]).Replace("%a", Data[1]).Replace("%d", Data[2]); + metroLabel2.Text = nam.Replace("%n", EI.Name).Replace("%a", EI.Author).Replace("%d", EI.Description).Replace("%pid", LocalTreeView.SelectedNode.Tag.ToString()); metroLabel2.AutoSize = false; metroLabel2.WrapToLine = true; - pictureBox2.Image = LocalCollections.GetLocalPackImage(packs[LocalTreeView.SelectedNode.Index], VitaCheckBox2.Checked); + pictureBox2.Image = LocalCollections.GetLocalPackImage(int.Parse(LocalTreeView.SelectedNode.Tag.ToString()), VitaCheckBox2.Checked); OpenFolderButton.Visible = true; DeleteLocalButton.Visible = true; } @@ -240,15 +230,16 @@ namespace PckStudio.Forms.Utilities case true: System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() { - FileName = Program.Appdata + "cache/packs/files/vita", + FileName = cache + "packs/vita/pcks", UseShellExecute = true, Verb = "open" }); break; case false: + Console.WriteLine(cache + "packs/normal/pcks/"); System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() { - FileName = Program.Appdata + "cache/packs/files", + FileName = cache + "packs/normal/pcks/", UseShellExecute = true, Verb = "open" }); @@ -258,37 +249,29 @@ namespace PckStudio.Forms.Utilities private void DeleteLocalButton_Click(object sender, EventArgs e) { - string[] packs = LocalCollections.GetLocalPackDescs(CategoryComboBoxLocal.Text, VitaCheckBox2.Checked); - if (MessageBox.Show("Are you sure you would like to remove '" + packs[LocalTreeView.SelectedNode.Index] + "'?", "Confirmation Dialog", MessageBoxButtons.YesNo) == DialogResult.Yes) + EntryInfo EI = LocalCollections.CenterPacks.Data[LocalTreeView.SelectedNode.Tag.ToString()]; + string PackID = LocalTreeView.SelectedNode.Tag.ToString(); + LActions.Removepack(LocalCollections.CenterPacks, int.Parse(PackID)); + metroLabel2.Text = "Pack Name: %n\npack ID: %pid\nAuthor: %a\nDescription: %d"; + pictureBox2.Image.Dispose(); + pictureBox2.Image = Properties.Resources.NoImageFound; + switch (VitaCheckBox2.Checked) { - pictureBox2.Image = Properties.Resources.NoImageFound; - switch (VitaCheckBox2.Checked) - { - case false: - string FileInfo = File.ReadAllText(Program.Appdata + "cache/packs/Category/Category" + CategoryComboBoxLocal.Text + ".txt"); - File.Delete(Program.Appdata + "cache/packs/files/" + packs[LocalTreeView.SelectedNode.Index] + ".pck"); - File.Delete(Program.Appdata + "cache/packs/descs/" + packs[LocalTreeView.SelectedNode.Index] + ".desc"); - try - { - File.Delete(Program.Appdata + "cache/packs/images/" + packs[LocalTreeView.SelectedNode.Index] + ".png"); - } - catch { } - File.WriteAllText(Program.Appdata + "cache/packs/Category/Category" + CategoryComboBoxLocal.Text + ".txt", FileInfo.Replace("\n" + packs[LocalTreeView.SelectedNode.Index], "")); - break; - case true: - string FileInfo2 = File.ReadAllText(Program.Appdata + "cache/packs/Category/VitaCategory" + CategoryComboBoxLocal.Text + ".txt"); - File.Delete(Program.Appdata + "cache/packs/files/Vita/" + packs[LocalTreeView.SelectedNode.Index] + ".pck"); - File.Delete(Program.Appdata + "cache/packs/descs/Vita/" + packs[LocalTreeView.SelectedNode.Index] + ".desc"); - try - { - File.Delete(Program.Appdata + "cache/packs/images/Vita/" + packs[LocalTreeView.SelectedNode.Index] + ".png"); - } - catch { } - File.WriteAllText(Program.Appdata + "cache/packs/Category/VitaCategory" + CategoryComboBoxLocal.Text + ".txt", FileInfo2.Replace("\n" + packs[LocalTreeView.SelectedNode.Index], "")); - break; - } - LocalTreeView.SelectedNode.Remove(); - metroLabel2.Text = "Pack Name: %n\nAuthor: %a\nDescription: %d"; + case true: + File.Delete(cache + "packs/vita/pcks/" + PackID + ".pck"); + File.Delete(cache + "packs/vita/images/" + PackID + ".png"); + break; + case false: + File.Delete(cache + "packs/normal/pcks/" + PackID + ".pck"); + File.Delete(cache + "packs/normal/images/" + PackID + ".png"); + break; + } + LocalTreeView.SelectedNode.Remove(); + switch (LActions.SaveLocalJSON(LocalCollections.CenterPacks, CategoryComboBoxLocal.Text, VitaCheckBox2.Checked)) + { + case false: + MessageBox.Show("Could not save JSON due to unknown error"); + break; } } diff --git a/MinecraftUSkinEditor/Forms/Utilities/pckCenter.cs b/MinecraftUSkinEditor/Forms/Utilities/pckCenter.cs index bfac00f2..4f6464b0 100644 --- a/MinecraftUSkinEditor/Forms/Utilities/pckCenter.cs +++ b/MinecraftUSkinEditor/Forms/Utilities/pckCenter.cs @@ -11,15 +11,18 @@ using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Media.Imaging; using RichPresenceClient; +using API.PCKCenter.model; +using API.PCKCenter; namespace PckStudio.Forms { public partial class pckCenter : MetroFramework.Forms.MetroForm { string[] mods; - string hosturl = File.ReadAllText(appData + "\\settings.ini").Split(new[] { "\r\n", "\n" }, StringSplitOptions.None)[1] + "/studio/PCK/api/"; - string loadDirectory = File.ReadAllText(appData + "\\settings.ini").Split(new[] { "\r\n", "\n" }, StringSplitOptions.None)[1] + "/studio/PCK/api/pckCenterList.txt"; + string hosturl = "http://pckstudio.xyz/studio/PCK/api/"; + string loadDirectory = "http://pckstudio.xyz/studio/PCK/api/pckCenterList.txt"; static string appData = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/PCK Studio/"; + LocalActions LAct = new LocalActions(); string cacheDir; bool nobleLoaded = true; @@ -88,6 +91,9 @@ namespace PckStudio.Forms control.Dispose(); } + PCKCenterJSON PJSON = new PCKCenterJSON(); + PJSON.Data = new Dictionary(); + int x = 0; foreach (string mod in mods) { try @@ -167,12 +173,22 @@ namespace PckStudio.Forms bool IsVita = (parseDesc[5] == "true" || parseDesc[5] == "True"); string Packname = parseDesc[6]; + EntryInfo EInfo = new EntryInfo(); + EInfo.Name = pckName; + EInfo.Author = author; + EInfo.Description = desc; + PJSON.Data.Add((++x).ToString(), EInfo); + File.Copy(cacheDir + mod + ".png", cacheDir + "images/" + ++x + ".png"); + + PckPreview pckPreview = new PckPreview(pckName, author, desc, direct, ad, bmp, 0, mod, null, IsVita, Packname); pckLayout.Controls.Add(pckPreview); } } - catch(Exception err) { Console.WriteLine(err.Message); } + catch (Exception err) { Console.WriteLine(err.Message); } + x++; } + LAct.SaveLocalJSON(PJSON, loadDirectory.Replace(hosturl + "pckCenter", "").Replace(".txt", ""), isVita); } } catch (Exception err) diff --git a/MinecraftUSkinEditor/PckStudio.csproj b/MinecraftUSkinEditor/PckStudio.csproj index 0324fffb..8f4fd9a8 100644 --- a/MinecraftUSkinEditor/PckStudio.csproj +++ b/MinecraftUSkinEditor/PckStudio.csproj @@ -136,6 +136,8 @@ + +