Add static strings to Program class

This commit is contained in:
miku-666
2022-08-31 20:36:18 +02:00
parent 7f4cbbb82d
commit 6f9f1f0e50
11 changed files with 47 additions and 59 deletions

View File

@@ -11,7 +11,7 @@ namespace API.PCKCenter
{
public class LocalActions
{
string cache = PckStudio.Program.Appdata + "cache/packs/";
string cache = PckStudio.Program.AppDataCache + "/packs/";
public bool SaveLocalJSON(PCKCenterJSON JSONData, string category, bool isVita)
{
try

View File

@@ -13,7 +13,7 @@ namespace PckStudio.Classes.IO
{
public class PCKCollectionsLocal
{
string cache = Program.Appdata + "cache/packs/";
static string cache = Program.AppDataCache + "/packs/";
public PCKCenterJSON CenterPacks;
public LocalActions LocalAction = new LocalActions();

View File

@@ -18,7 +18,7 @@ namespace PckStudio.Classes.Networking
{
WebClient client = new WebClient();
public string CurrentPackDl = "";
string cache = Program.Appdata + "cache/packs/";
string cache = Program.AppDataCache + "/packs/";
public PCKCenterJSON CenterPacks;
public LocalActions LocalAction = new LocalActions();
public string[] GetCategories()
@@ -26,11 +26,11 @@ namespace PckStudio.Classes.Networking
string cat = "";
try
{
cat = client.DownloadString(Program.baseurl + "/center/packs/Categiories.json");
cat = client.DownloadString(Program.BaseAPIUrl + "/center/packs/Categiories.json");
}
catch
{
cat = client.DownloadString(Program.baseurl + "/center/packs/VitaCategiories.json");
cat = client.DownloadString(Program.BaseAPIUrl + "/center/packs/VitaCategiories.json");
}
return JsonConvert.DeserializeObject<string[]>(cat);
}
@@ -43,10 +43,10 @@ namespace PckStudio.Classes.Networking
switch (IsVita)
{
case (true):
cat = client.DownloadString(Program.baseurl + "/center/packs/vita/" + Category + ".json");
cat = client.DownloadString(Program.BaseAPIUrl + "/center/packs/vita/" + Category + ".json");
break;
case (false):
cat = client.DownloadString(Program.baseurl + "/center/packs/normal/" + Category + ".json");
cat = client.DownloadString(Program.BaseAPIUrl + "/center/packs/normal/" + Category + ".json");
break;
}
}
@@ -55,10 +55,10 @@ namespace PckStudio.Classes.Networking
switch (IsVita)
{
case (true):
cat = client.DownloadString(Program.backurl + "/center/packs/vita/" + Category + ".json");
cat = client.DownloadString(Program.BackUpAPIUrl + "/center/packs/vita/" + Category + ".json");
break;
case (false):
cat = client.DownloadString(Program.backurl + "/center/packs/normal/" + Category + ".json");
cat = client.DownloadString(Program.BackUpAPIUrl + "/center/packs/normal/" + Category + ".json");
break;
}
}
@@ -104,10 +104,10 @@ namespace PckStudio.Classes.Networking
switch (IsVita)
{
case (true):
cat = client.DownloadData(Program.baseurl + "/center/packs/vita/images/" + packID + ".png");
cat = client.DownloadData(Program.BaseAPIUrl + "/center/packs/vita/images/" + packID + ".png");
break;
case (false):
cat = client.DownloadData(Program.baseurl + "/center/packs/normal/images/" + packID + ".png");
cat = client.DownloadData(Program.BaseAPIUrl + "/center/packs/normal/images/" + packID + ".png");
break;
}
}
@@ -116,10 +116,10 @@ namespace PckStudio.Classes.Networking
switch (IsVita)
{
case (true):
cat = client.DownloadData(Program.backurl + "/center/packs/vita/images/" + packID + ".png");
cat = client.DownloadData(Program.BackUpAPIUrl + "/center/packs/vita/images/" + packID + ".png");
break;
case (false):
cat = client.DownloadData(Program.backurl + "/center/packs/normal/images/" + packID + ".png");
cat = client.DownloadData(Program.BackUpAPIUrl + "/center/packs/normal/images/" + packID + ".png");
break;
}
}
@@ -149,11 +149,11 @@ namespace PckStudio.Classes.Networking
{
case (false):
image.Save(cache + "normal/images/" + packID + ".png");
client.DownloadFile(Program.baseurl + "/center/packs/normal/pcks/" + packID + ".pck", cache + "normal/pcks/" + packID + ".pck");
client.DownloadFile(Program.BaseAPIUrl + "/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");
client.DownloadFile(Program.BaseAPIUrl + "/center/packs/vita/pcks/" + packID + ".pck", cache + "vita/pcks/" + packID + ".pck");
break;
}
Local = LocalAction.AddPack(Local, CenterPacks.Data[packID.ToString()], packID);
@@ -174,7 +174,7 @@ namespace PckStudio.Classes.Networking
try
{
WebClient wc = new WebClient();
string CategoryJSON = wc.DownloadString(Program.baseurl + "/center/packs/Categiories.json");
string CategoryJSON = wc.DownloadString(Program.BaseAPIUrl + "/center/packs/Categiories.json");
string[] Categories = JsonConvert.DeserializeObject<string[]>(CategoryJSON);
PCKCenterJSON Result = pk1(Categories[2]);
Console.Write(""); // this is a breakpoint
@@ -188,7 +188,7 @@ namespace PckStudio.Classes.Networking
PCKCenterJSON pk1(string categorie)
{
WebClient wc = new WebClient();
string DataJSON = wc.DownloadString(Program.baseurl + "/center/packs/normal/" + categorie + ".json");
string DataJSON = wc.DownloadString(Program.BaseAPIUrl + "/center/packs/normal/" + categorie + ".json");
PCKCenterJSON Data = JsonConvert.DeserializeObject<PCKCenterJSON>(DataJSON);
return Data;
}

View File

@@ -26,7 +26,7 @@ namespace PckStudio.Forms
private void Job_Load(object sender, EventArgs e)
{
File.Create(Program.Appdata + "\\discordmark");
File.Create(Program.AppData + "\\discordmark");
}
private void buttonDonate_Click(object sender, EventArgs e)

View File

@@ -29,7 +29,7 @@ namespace PckStudio.Forms
private void goodbye_Load(object sender, EventArgs e)
{
System.IO.File.Create(Program.Appdata + "\\goodbyemark");
System.IO.File.Create(Program.AppData + "\\goodbyemark");
}
}
}

View File

@@ -35,15 +35,10 @@ namespace PckStudio.Forms.Utilities
}
}
#region variables
public PCKCollections Collections = new PCKCollections();
public PCKCollectionsLocal LocalCollections = new PCKCollectionsLocal();
LocalActions LActions = new LocalActions();
string cache = Program.Appdata + "cache/";
#endregion
string cache = Program.AppDataCache;
#region Functions
public void GetCategories()
@@ -75,8 +70,7 @@ namespace PckStudio.Forms.Utilities
LocalTreeView.Nodes.Clear();
DownloadButton.Visible = false;
pictureBox1.Image = Properties.Resources.pckCenterHeader;
pictureBox2.Image = Properties.Resources.pckCenterHeader;
pictureBox1.Image = pictureBox2.Image = Properties.Resources.pckCenterHeader;
switch (metroTabControl1.SelectedIndex)
{
@@ -107,17 +101,9 @@ namespace PckStudio.Forms.Utilities
}
}
public bool IsPackLocal(int PackID, bool IsVita)
public bool IsPackLocal(int packID, bool isVita)
{
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;
}
return File.Exists(cache + $"packs/{(isVita ? "vita" : "normal")}/pcks/" + packID + ".pck");
}
#endregion
@@ -126,10 +112,11 @@ namespace PckStudio.Forms.Utilities
{
try
{
string nam = "Pack Name: %n\npack ID: %pid\nAuthor: %a\nDescription: %d";
EntryInfo EI = Collections.CenterPacks.Data[OnlineTreeView.SelectedNode.Tag.ToString()];
string nam = string.Format("Pack Name: {0}\npack ID: {1}\nAuthor: {2}\nDescription: {3}",
EI.Name, OnlineTreeView.SelectedNode.Tag.ToString(), EI.Author, EI.Description);
metroLabel1.Text = nam.Replace("%n", EI.Name).Replace("%a", EI.Author).Replace("%d", EI.Description).Replace("%pid", OnlineTreeView.SelectedNode.Tag.ToString());
metroLabel1.Text = nam;
metroLabel1.AutoSize = false;
metroLabel1.WrapToLine = true;

View File

@@ -443,8 +443,8 @@ namespace PckStudio.Forms
private void GetARCFromConsole()
{
FTP client = new FTP("ftp://" + textBoxHost.Text, "", "a3262443");
client.DownloadFile(dlcPath + "../../Common/Media/MediaWiiU.arc", Program.Appdata + "MediaWiiU.arc");
archive = ARCFileReader.Read(new MemoryStream(File.ReadAllBytes(Program.Appdata + "MediaWiiU.arc")));
client.DownloadFile(dlcPath + "../../Common/Media/MediaWiiU.arc", Program.AppData + "MediaWiiU.arc");
archive = ARCFileReader.Read(new MemoryStream(File.ReadAllBytes(Program.AppData + "MediaWiiU.arc")));
}
private void ReplacePackImage(string PackID)
@@ -459,8 +459,8 @@ namespace PckStudio.Forms
FTP client = new FTP("ftp://" + textBoxHost.Text, "", "a3262443");
MemoryStream ms = new MemoryStream();
ARCFileWriter.Write(ms, archive);
File.WriteAllBytes(Program.Appdata + "MediaWiiU.arc", ms.ToArray());
client.UploadFile(Program.Appdata + "MediaWiiU.arc", dlcPath + "../../Common/Media/MediaWiiU.arc");
File.WriteAllBytes(Program.AppData + "MediaWiiU.arc", ms.ToArray());
client.UploadFile(Program.AppData + "MediaWiiU.arc", dlcPath + "../../Common/Media/MediaWiiU.arc");
archive.Clear();
currentPCK.Files.Clear();
currentPCK = null;

View File

@@ -21,9 +21,9 @@ namespace PckStudio.Forms
string[] mods;
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/";
static string appData = Program.AppData;
LocalActions LAct = new LocalActions();
string cacheDir;
string cacheDir = Program.AppDataCache + "/mods/";
bool nobleLoaded = true;
bool newLoaded = true;
@@ -38,8 +38,6 @@ namespace PckStudio.Forms
InitializeComponent();
//listViewNav.SmallImageList = imgList;
cacheDir = appData + "\\cache\\mods\\";
if (!Directory.Exists(cacheDir))
{
Directory.CreateDirectory(cacheDir);

View File

@@ -133,7 +133,7 @@ namespace PckStudio.Forms
List<PCKFile.FileData> capesList = new List<PCKFile.FileData>();
PCKFile pck = null;
using (var stream = File.OpenRead(Program.Appdata + "/PCK-Center/myPcks/" + mod + ".pck"))
using (var stream = File.OpenRead(Program.AppData + "/PCK-Center/myPcks/" + mod + ".pck"))
{
pck = PCKFileReader.Read(stream, false); // sets opened pck
}
@@ -1102,9 +1102,10 @@ namespace PckStudio.Forms
{
try
{
File.Delete(Program.Appdata + "/PCK-Center/myPcks/" + mod + ".pck");
File.Delete(Program.Appdata + "/PCK-Center/myPcks/" + mod + ".png");
File.Delete(Program.Appdata + "/PCK-Center/myPcks/" + mod + ".desc");
File.Delete(Program.AppData + "/PCK-Center/myPcks/" + mod + ".pck");
File.Delete(Program.AppData + "/PCK-Center/myPcks/" + mod + ".pck");
File.Delete(Program.AppData + "/PCK-Center/myPcks/" + mod + ".png");
File.Delete(Program.AppData + "/PCK-Center/myPcks/" + mod + ".desc");
reloader();
}
catch (Exception)
@@ -1124,7 +1125,7 @@ namespace PckStudio.Forms
{
try
{
File.Copy(Program.Appdata + "/PCK-Center/myPcks/" + mod + ".pck", export.FileName);
File.Copy(Program.AppData + "/PCK-Center/myPcks/" + mod + ".pck", export.FileName);
MessageBox.Show("PCK Received from location!");
}catch (Exception)
{
@@ -1145,7 +1146,7 @@ namespace PckStudio.Forms
private void buttonInstallWiiU_Click(object sender, EventArgs e)
{
installWiiU install = new installWiiU(Program.Appdata + "/PCK Center/myPcks/" + mod + ".pck");
installWiiU install = new installWiiU(Program.AppData + "/PCK Center/myPcks/" + mod + ".pck");
install.ShowDialog();
}
}

View File

@@ -78,7 +78,7 @@ namespace PckStudio
try
{
Directory.CreateDirectory(Program.Appdata + "\\cache\\mods\\");
Directory.CreateDirectory(Program.AppDataCache + "\\mods\\");
}
catch (UnauthorizedAccessException ex)
{
@@ -2750,9 +2750,9 @@ namespace PckStudio
private void FormMain_FormClosed(object sender, FormClosedEventArgs e)
{
if (needsUpdate && File.Exists(Program.Appdata + @"\nobleUpdater.exe"))
if (needsUpdate && File.Exists(Program.AppData + @"\nobleUpdater.exe"))
{
Process.Start(Program.Appdata + @"\nobleUpdater.exe"); // starts updater
Process.Start(Program.AppData + @"\nobleUpdater.exe"); // starts updater
Application.Exit(); // closes PCK Studio to let updatear finish the job
}
}

View File

@@ -1,13 +1,15 @@
using System;
using System.IO;
using System.Windows.Forms;
namespace PckStudio
{
static class Program
{
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 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/PCK-Studio/";
public static string BaseAPIUrl = "http://api.pckstudio.xyz/api/pck";
public static string BackUpAPIUrl = "https://raw.githubusercontent.com/PhoenixARC/pckstudio.tk/main/studio/PCK/api/";
public static string AppData = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "PCK-Studio");
public static string AppDataCache = Path.Combine(AppData, "cache");
/// <summary>
/// The main entry point for the application.
/// </summary>