FINALLY fixed the asset fixer

This commit is contained in:
Bitl 2022-08-06 11:06:52 -07:00
parent 21e1af249e
commit 12ca4d2f4a
2 changed files with 87 additions and 69 deletions

View File

@ -39,7 +39,6 @@
this.AssetLocalization_AssetTypeText = new System.Windows.Forms.Label(); this.AssetLocalization_AssetTypeText = new System.Windows.Forms.Label();
this.AssetLocalization_ItemNameText = new System.Windows.Forms.Label(); this.AssetLocalization_ItemNameText = new System.Windows.Forms.Label();
this.AssetLocalization_ItemNameBox = new System.Windows.Forms.TextBox(); this.AssetLocalization_ItemNameBox = new System.Windows.Forms.TextBox();
this.AssetLocalization_StatusText = new System.Windows.Forms.Label();
this.AssetLocalization_AssetTypeBox = new System.Windows.Forms.ComboBox(); this.AssetLocalization_AssetTypeBox = new System.Windows.Forms.ComboBox();
this.AssetLocalization_LocalizeButton = new System.Windows.Forms.Button(); this.AssetLocalization_LocalizeButton = new System.Windows.Forms.Button();
this.AssetLocalization_BackgroundWorker = new System.ComponentModel.BackgroundWorker(); this.AssetLocalization_BackgroundWorker = new System.ComponentModel.BackgroundWorker();
@ -85,15 +84,16 @@
// //
// AssetFixer_ProgressLabel // AssetFixer_ProgressLabel
// //
this.AssetFixer_ProgressLabel.Location = new System.Drawing.Point(12, 254); this.AssetFixer_ProgressLabel.Location = new System.Drawing.Point(12, 217);
this.AssetFixer_ProgressLabel.Name = "AssetFixer_ProgressLabel"; this.AssetFixer_ProgressLabel.Name = "AssetFixer_ProgressLabel";
this.AssetFixer_ProgressLabel.Size = new System.Drawing.Size(278, 18); this.AssetFixer_ProgressLabel.Size = new System.Drawing.Size(278, 18);
this.AssetFixer_ProgressLabel.TabIndex = 24; this.AssetFixer_ProgressLabel.TabIndex = 24;
this.AssetFixer_ProgressLabel.Text = "Idle";
this.AssetFixer_ProgressLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; this.AssetFixer_ProgressLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
// //
// AssetFixer_ProgressBar // AssetFixer_ProgressBar
// //
this.AssetFixer_ProgressBar.Location = new System.Drawing.Point(12, 228); this.AssetFixer_ProgressBar.Location = new System.Drawing.Point(12, 191);
this.AssetFixer_ProgressBar.Name = "AssetFixer_ProgressBar"; this.AssetFixer_ProgressBar.Name = "AssetFixer_ProgressBar";
this.AssetFixer_ProgressBar.Size = new System.Drawing.Size(278, 23); this.AssetFixer_ProgressBar.Size = new System.Drawing.Size(278, 23);
this.AssetFixer_ProgressBar.TabIndex = 23; this.AssetFixer_ProgressBar.TabIndex = 23;
@ -158,16 +158,6 @@
this.AssetLocalization_ItemNameBox.TabIndex = 14; this.AssetLocalization_ItemNameBox.TabIndex = 14;
this.AssetLocalization_ItemNameBox.TextChanged += new System.EventHandler(this.AssetLocalization_ItemNameBox_TextChanged); this.AssetLocalization_ItemNameBox.TextChanged += new System.EventHandler(this.AssetLocalization_ItemNameBox_TextChanged);
// //
// AssetLocalization_StatusText
//
this.AssetLocalization_StatusText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.AssetLocalization_StatusText.Location = new System.Drawing.Point(12, 188);
this.AssetLocalization_StatusText.Name = "AssetLocalization_StatusText";
this.AssetLocalization_StatusText.Size = new System.Drawing.Size(278, 36);
this.AssetLocalization_StatusText.TabIndex = 13;
this.AssetLocalization_StatusText.Text = "Idle";
this.AssetLocalization_StatusText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// AssetLocalization_AssetTypeBox // AssetLocalization_AssetTypeBox
// //
this.AssetLocalization_AssetTypeBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.AssetLocalization_AssetTypeBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@ -205,7 +195,7 @@
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.ControlLightLight; this.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.ClientSize = new System.Drawing.Size(302, 281); this.ClientSize = new System.Drawing.Size(302, 241);
this.Controls.Add(this.AssetFixer_ProgressLabel); this.Controls.Add(this.AssetFixer_ProgressLabel);
this.Controls.Add(this.URLOverrideBox); this.Controls.Add(this.URLOverrideBox);
this.Controls.Add(this.AssetFixer_ProgressBar); this.Controls.Add(this.AssetFixer_ProgressBar);
@ -216,7 +206,6 @@
this.Controls.Add(this.AssetLocalization_SaveBackups); this.Controls.Add(this.AssetLocalization_SaveBackups);
this.Controls.Add(this.URLSelection); this.Controls.Add(this.URLSelection);
this.Controls.Add(this.AssetLocalization_AssetTypeText); this.Controls.Add(this.AssetLocalization_AssetTypeText);
this.Controls.Add(this.AssetLocalization_StatusText);
this.Controls.Add(this.AssetLocalization_ItemNameText); this.Controls.Add(this.AssetLocalization_ItemNameText);
this.Controls.Add(this.AssetLocalization_LocalizeButton); this.Controls.Add(this.AssetLocalization_LocalizeButton);
this.Controls.Add(this.AssetLocalization_ItemNameBox); this.Controls.Add(this.AssetLocalization_ItemNameBox);
@ -239,7 +228,6 @@
private System.Windows.Forms.Label AssetLocalization_AssetTypeText; private System.Windows.Forms.Label AssetLocalization_AssetTypeText;
private System.Windows.Forms.Label AssetLocalization_ItemNameText; private System.Windows.Forms.Label AssetLocalization_ItemNameText;
private System.Windows.Forms.TextBox AssetLocalization_ItemNameBox; private System.Windows.Forms.TextBox AssetLocalization_ItemNameBox;
private System.Windows.Forms.Label AssetLocalization_StatusText;
private System.Windows.Forms.ComboBox AssetLocalization_AssetTypeBox; private System.Windows.Forms.ComboBox AssetLocalization_AssetTypeBox;
private System.Windows.Forms.Button AssetLocalization_LocalizeButton; private System.Windows.Forms.Button AssetLocalization_LocalizeButton;
private System.Windows.Forms.ComboBox URLSelection; private System.Windows.Forms.ComboBox URLSelection;

View File

@ -151,7 +151,11 @@ public partial class AssetFixer : Form
void ProgressChangedEvent() void ProgressChangedEvent()
{ {
AssetFixer_ProgressBar.Value += 1; if (AssetFixer_ProgressBar.Value < AssetFixer_ProgressBar.Maximum)
{
AssetFixer_ProgressBar.Value += 1;
}
AssetFixer_ProgressLabel.Text = "Progress: " + AssetFixer_ProgressBar.Value.ToString() + "/" + AssetFixer_ProgressBar.Maximum.ToString(); AssetFixer_ProgressLabel.Text = "Progress: " + AssetFixer_ProgressBar.Value.ToString() + "/" + AssetFixer_ProgressBar.Maximum.ToString();
} }
@ -159,33 +163,45 @@ public partial class AssetFixer : Form
{ {
string[] file = File.ReadAllLines(filepath); string[] file = File.ReadAllLines(filepath);
int index = 0; int length = 0;
AssetFixer_ProgressBar.Maximum = file.Length;
foreach (var line in file) foreach (var line in file)
{ {
++index; if (line.Contains("www.w3.org") || line.Contains("roblox.xsd"))
try
{ {
if (line.Contains("www.w3.org") || line.Contains("roblox.xsd")) continue;
{ }
ProgressChangedEvent();
continue;
}
string oneline = Regex.Replace(line, @"\t|\n|\r", ""); if (!(line.Contains("http://") || line.Contains("https://")))
AssetLocalization_StatusText.Text = (!useURLs ? "Localizing " : "Fixing " ) + oneline; {
AssetLocalization_StatusText.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; continue;
}
if (!useURLs) length++;
}
AssetFixer_ProgressBar.Maximum = length;
while (AssetFixer_ProgressBar.Value < AssetFixer_ProgressBar.Maximum)
{
int index = 0;
foreach (var line in file)
{
++index;
try
{ {
if (line.Contains("www.w3.org") || line.Contains("roblox.xsd"))
{
continue;
}
if (line.Contains("http://") || line.Contains("https://")) if (line.Contains("http://") || line.Contains("https://"))
{ {
//https://stackoverflow.com/questions/10576686/c-sharp-regex-pattern-to-extract-urls-from-given-string-not-full-html-urls-but //https://stackoverflow.com/questions/10576686/c-sharp-regex-pattern-to-extract-urls-from-given-string-not-full-html-urls-but
List<string> links = new List<string>(); List<string> links = new List<string>();
var linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase); var linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b(?=<| )", RegexOptions.Compiled | RegexOptions.IgnoreCase);
foreach (Match m in linkParser.Matches(line)) foreach (Match m in linkParser.Matches(line))
{ {
string link = m.Value; string link = m.Value;
@ -194,48 +210,64 @@ public partial class AssetFixer : Form
foreach (string link in links) foreach (string link in links)
{ {
string newurl = ((!link.Contains("http://") || !link.Contains("https://")) ? "https://" : "") if (link.Contains(".png") || link.Contains(".jpg") || link.Contains(".jpeg"))
{
continue;
}
if (link.Contains("my-roblox-character-item"))
{
continue;
}
string urlFixed = "";
if (useURLs)
{
string oldurl = line;
urlFixed = GlobalFuncs.FixURLString(oldurl, url);
}
else
{
string newurl = ((!link.Contains("http://") || !link.Contains("https://")) ? "https://" : "")
+ "assetdelivery.roblox.com/v1/asset/?id="; + "assetdelivery.roblox.com/v1/asset/?id=";
string urlReplaced = newurl.Contains("https://") ? link.Replace("http://", "").Replace("https://", "") : link.Replace("http://", "https://"); string urlReplaced = newurl.Contains("https://") ? link.Replace("http://", "").Replace("https://", "") : link.Replace("http://", "https://");
string urlFixed = GlobalFuncs.FixURLString(urlReplaced, newurl); urlFixed = GlobalFuncs.FixURLString(urlReplaced, newurl);
}
string peram = "id="; string peram = "id=";
if (urlFixed.Contains(peram)) if (urlFixed.Contains(peram))
{ {
string IDVal = urlFixed.After(peram); if (useURLs)
RobloxXML.DownloadFilesFromNode(urlFixed, savefilepath, "", IDVal); {
file[index - 1] = file[index - 1].Replace(link, inGameDir + IDVal); file[index - 1] = file[index - 1].Replace(link, urlFixed);
}
else
{
string IDVal = urlFixed.After(peram);
RobloxXML.DownloadFilesFromNode(urlFixed, savefilepath, "", IDVal);
file[index - 1] = file[index - 1].Replace(link, inGameDir + IDVal);
}
} }
} }
ProgressChangedEvent();
} }
} else
else
{
if ((line.Contains("http://") || line.Contains("https://")) && !line.Contains(url))
{ {
string oldurl = line; continue;
string urlFixed = GlobalFuncs.FixURLString(oldurl, url);
string peram = "id=";
if (urlFixed.Contains(peram))
{
file[index - 1] = urlFixed;
}
} }
} }
catch (Exception ex)
ProgressChangedEvent(); {
} GlobalFuncs.LogExceptions(ex);
catch (Exception ex) errors += 1;
{ GlobalFuncs.LogPrint("ASSETFIX|FILE " + path + " LINE #" + (index) + " " + ex.Message, 2);
GlobalFuncs.LogExceptions(ex); GlobalFuncs.LogPrint("ASSETFIX|Asset might be private or unavailable.");
errors += 1; ProgressChangedEvent();
GlobalFuncs.LogPrint("ASSETFIX|FILE " + path + " LINE #" + (index) + " " + ex.Message, 2); continue;
GlobalFuncs.LogPrint("ASSETFIX|Asset might be private or unavailable."); }
ProgressChangedEvent();
continue;
} }
} }
@ -401,16 +433,16 @@ public partial class AssetFixer : Form
switch (e) switch (e)
{ {
case RunWorkerCompletedEventArgs can when can.Cancelled: case RunWorkerCompletedEventArgs can when can.Cancelled:
AssetLocalization_StatusText.Text = "Canceled!"; AssetFixer_ProgressLabel.Text = "Canceled!";
break; break;
case RunWorkerCompletedEventArgs err when err.Error != null: case RunWorkerCompletedEventArgs err when err.Error != null:
AssetLocalization_StatusText.Text = "Error: " + e.Error.Message; AssetFixer_ProgressLabel.Text = "Error: " + e.Error.Message;
MessageBox.Show("Error: " + e.Error.Message + "\n\n" + e.Error.StackTrace, "Asset Fixer - Error", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Error: " + e.Error.Message + "\n\n" + e.Error.StackTrace, "Asset Fixer - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
break; break;
default: default:
if (errors > 0) if (errors > 0)
{ {
AssetLocalization_StatusText.Text = "Completed with " + errors + " errors!"; AssetFixer_ProgressLabel.Text = "Completed with " + errors + " errors!";
string errorCountString = errors + ((errors == 1 || errors == -1) ? " error" : " errors"); string errorCountString = errors + ((errors == 1 || errors == -1) ? " error" : " errors");
@ -423,14 +455,12 @@ public partial class AssetFixer : Form
} }
else else
{ {
AssetLocalization_StatusText.Text = "Completed!"; AssetFixer_ProgressLabel.Text = "Completed!";
} }
break; break;
} }
AssetLocalization_StatusText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
AssetFixer_ProgressBar.Value = 0; AssetFixer_ProgressBar.Value = 0;
AssetFixer_ProgressLabel.Text = "";
} }
private void AssetLocalization_LocalizePermanentlyBox_Click(object sender, EventArgs e) private void AssetLocalization_LocalizePermanentlyBox_Click(object sender, EventArgs e)