Skip to content

Commit

Permalink
ocd
Browse files Browse the repository at this point in the history
  • Loading branch information
MistressPlague committed Dec 23, 2023
1 parent 766268b commit 32d0329
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions Easy Minecraft Modpacks/MainUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEvent
var filename = client.GetFileName(value);

var name = Regex.Match(filename, @"[a-zA-Z _\-]*").Value;

var modName = (!string.IsNullOrWhiteSpace(name) ? name : "").Replace("-", " ").Trim();

modName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(modName).Replace("Api", "API").Replace("Fabric", "").Replace("Forge", "").Trim();

dataGridView1.Rows[e.RowIndex].Cells["ModName"].Value = modName;
Expand All @@ -174,7 +174,7 @@ private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEvent
}
}
}

UpdateRows();
}
}
Expand Down Expand Up @@ -355,7 +355,7 @@ private void UpdateRows()

private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
UpdateRows();
UpdateRows();
}

private void dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
Expand All @@ -380,18 +380,18 @@ public static string BetterDownloadFile(this WebClient client, string url, strin
var redir = Workarounds.GetRedirectedUrl(url);

var disposition = client.ResponseHeaders["Content-Disposition"];

var locationEnding = redir?.Substring(redir.LastIndexOf("/", StringComparison.Ordinal) + 1);

var hasQuery = locationEnding?.IndexOf("?", StringComparison.Ordinal) ?? -1;

if (hasQuery != -1)
{
locationEnding = locationEnding?.Substring(0, hasQuery);
}

var urlEnding = url.Substring(url.LastIndexOf("/", StringComparison.Ordinal) + 1);

var filename = Workarounds.UrlDecode(disposition != null ? new ContentDisposition(disposition).FileName : (locationEnding != null ? locationEnding : urlEnding));

File.WriteAllBytes($"{targetDir}\\{filename}", data);
Expand All @@ -414,18 +414,18 @@ public static string GetFileName(this WebClient client, string url)
var redir = Workarounds.GetRedirectedUrl(url);

var disposition = client.ResponseHeaders["Content-Disposition"];

var locationEnding = redir?.Substring(redir.LastIndexOf("/", StringComparison.Ordinal) + 1);

var hasQuery = locationEnding?.IndexOf("?", StringComparison.Ordinal) ?? -1;

if (hasQuery != -1)
{
locationEnding = locationEnding?.Substring(0, hasQuery);
}

var urlEnding = url.Substring(url.LastIndexOf("/", StringComparison.Ordinal) + 1);

var filename = Workarounds.UrlDecode(disposition != null ? new ContentDisposition(disposition).FileName : (locationEnding != null ? locationEnding : urlEnding));

return filename;
Expand All @@ -438,7 +438,7 @@ public static string UrlDecode(string url)
{
return Uri.UnescapeDataString(url);
}

public static string GetRedirectedUrl(string url)
{
HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(url);
Expand All @@ -457,15 +457,15 @@ public static string GetRedirectedUrl(string url)
}
}
}
catch(System.Net.WebException e)
catch (System.Net.WebException e)
{
if(e.Status == WebExceptionStatus.ProtocolError)
if (e.Status == WebExceptionStatus.ProtocolError)
{
var response = (HttpWebResponse)e.Response;
if(response.StatusCode == HttpStatusCode.Redirect
|| response.StatusCode == HttpStatusCode.MovedPermanently
|| response.StatusCode == HttpStatusCode.TemporaryRedirect
)
if (response.StatusCode == HttpStatusCode.Redirect
|| response.StatusCode == HttpStatusCode.MovedPermanently
|| response.StatusCode == HttpStatusCode.TemporaryRedirect
)
{
return response.Headers["Location"];
}
Expand Down

0 comments on commit 32d0329

Please sign in to comment.