Skip to content

Commit

Permalink
Remove "Arcade-" prefix and stuff...
Browse files Browse the repository at this point in the history
Added remove "Arcade-" prefix option; added Other Authors Scripts and NeoGeo romsets.xml to Extras; fixed Extras regular expression.
  • Loading branch information
Locutus73 authored Oct 5, 2019
1 parent 2e8053d commit 9112163
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 26 deletions.
36 changes: 31 additions & 5 deletions MiSTerConfigurator/ConfiguratorForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 35 additions & 21 deletions MiSTerConfigurator/ConfiguratorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.Text.RegularExpressions;
using System.IO;

Expand Down Expand Up @@ -263,7 +262,7 @@ private void saveWiFi()

#region "Cores business logic"

private void downloadCores(System.Windows.Forms.TreeNodeCollection Nodes, String currentDirectory, String workDirectory)
private void downloadCores(System.Windows.Forms.TreeNodeCollection Nodes, String currentDirectory, String workDirectory, bool removeArcadePrefix)
{
foreach (System.Windows.Forms.TreeNode objNode in Nodes)
{
Expand All @@ -285,16 +284,16 @@ private void downloadCores(System.Windows.Forms.TreeNodeCollection Nodes, String
currentDirectory = Path.Combine(getControlText_TS(cmbMiSTerDir), getControlText_TS(txtUtilityDir));
break;
};
downloadCores(objNode.Nodes, currentDirectory, workDirectory);
downloadCores(objNode.Nodes, currentDirectory, workDirectory, removeArcadePrefix);
}
else
{
if (objNode.Checked) downloadCore(objNode.Text, objNode.Tag.ToString(), currentDirectory, workDirectory);
if (objNode.Checked) downloadCore(objNode.Text, objNode.Tag.ToString(), currentDirectory, workDirectory, removeArcadePrefix);
};
};
}

private delegate void delegateDownloadCores(System.Windows.Forms.TreeNodeCollection Nodes, String currentDirectory, String workDirectory);
private delegate void delegateDownloadCores(System.Windows.Forms.TreeNodeCollection Nodes, String currentDirectory, String workDirectory, bool removeArcadePrefix);
private void asyncDownloadCoresCallBack(IAsyncResult AsyncResult)
{
((delegateDownloadCores)AsyncResult.AsyncState).EndInvoke(AsyncResult);
Expand All @@ -305,15 +304,15 @@ private void asyncDownloadCoresCallBack(IAsyncResult AsyncResult)
asyncDownloadExtras(treeViewExtras.Nodes, getControlText_TS(cmbMiSTerDir));
};
}
private void asyncDownloadCores(System.Windows.Forms.TreeNodeCollection Nodes, String currentDirectory, String workDirectory)
private void asyncDownloadCores(System.Windows.Forms.TreeNodeCollection Nodes, String currentDirectory, String workDirectory, bool removeArcadePrefix)
{
delegateDownloadCores objDelegateDownloadCores = new delegateDownloadCores(downloadCores);
objDelegateDownloadCores.BeginInvoke(Nodes, currentDirectory, workDirectory, asyncDownloadCoresCallBack, objDelegateDownloadCores);
objDelegateDownloadCores.BeginInvoke(Nodes, currentDirectory, workDirectory, removeArcadePrefix, asyncDownloadCoresCallBack, objDelegateDownloadCores);
}

readonly Regex objRegExCoreReleasesURL = new Regex("/MiSTer-devel/[a-zA-Z0-9./_-]*/tree/[a-zA-Z0-9./_-]*/releases", RegexOptions.Compiled);
readonly Regex objRegExCoreReleases = new Regex("/MiSTer-devel/.*/(?<FileName>(?<BaseName>[a-zA-Z0-9._-]*)_(?<TimeStamp>[0-9]{8}[a-zA-Z]?)(?<FileExtension>\\.rbf|\\.rar)?)", RegexOptions.Compiled);
private void downloadCore(String coreName, String coreURL, String coreDirectory, String workDirectory)
private void downloadCore(String coreName, String coreURL, String coreDirectory, String workDirectory, bool removeArcadePrefix)
{
String strReleases;
Match objMaxReleaseMatch = null;
Expand All @@ -322,6 +321,7 @@ private void downloadCore(String coreName, String coreURL, String coreDirectory,
Match objMaxLocalFileMatch = null;
String strDestinationFile = null;
String strDestinationDirectory = null;
String strBaseName = null;

writeStatusLabel_TS("Checking " + coreName);
Application.DoEvents();
Expand All @@ -340,7 +340,7 @@ private void downloadCore(String coreName, String coreURL, String coreDirectory,
};
foreach (Match objMatch in objRegExCoreReleases.Matches(strReleases))
{
if ((coreName.CompareTo("Atari 800XL")!=0 || objMatch.Groups["BaseName"].Value.CompareTo("Atari800")==0) && (coreName.CompareTo("Atari 5200")!=0 || objMatch.Groups["BaseName"].Value.CompareTo("Atari5200")==0))
if ((coreName.CompareTo("Atari 800XL") != 0 || objMatch.Groups["BaseName"].Value.CompareTo("Atari800") == 0) && (coreName.CompareTo("Atari 5200") != 0 || objMatch.Groups["BaseName"].Value.CompareTo("Atari5200") == 0))
{
if (objMaxReleaseMatch == null || objMatch.Groups["TimeStamp"].Value.CompareTo(objMaxReleaseMatch.Groups["TimeStamp"].Value) > 0)
{
Expand All @@ -350,7 +350,9 @@ private void downloadCore(String coreName, String coreURL, String coreDirectory,
};
if (objMaxReleaseMatch != null)
{
switch (objMaxReleaseMatch.Groups["BaseName"].Value)
strBaseName = objMaxReleaseMatch.Groups["BaseName"].Value;
if (removeArcadePrefix && strBaseName.StartsWith("Arcade-")) strBaseName = strBaseName.Remove(0, 7);
switch (strBaseName)
{
case "MiSTer":
case "menu":
Expand All @@ -362,8 +364,8 @@ private void downloadCore(String coreName, String coreURL, String coreDirectory,
};
if (Directory.Exists(strDestinationDirectory))
{
objRegExLocalFiles = new Regex(objMaxReleaseMatch.Groups["BaseName"].Value + "_(?<TimeStamp>[0-9]{8}[a-zA-Z]?)" + objMaxReleaseMatch.Groups["FileExtension"].Value.Replace(".", "\\.") + "$");
foreach (String strFile in Directory.GetFiles(strDestinationDirectory, objMaxReleaseMatch.Groups["BaseName"].Value + "*" + objMaxReleaseMatch.Groups["FileExtension"].Value))
objRegExLocalFiles = new Regex(strBaseName + "_(?<TimeStamp>[0-9]{8}[a-zA-Z]?)" + objMaxReleaseMatch.Groups["FileExtension"].Value.Replace(".", "\\.") + "$");
foreach (String strFile in Directory.GetFiles(strDestinationDirectory, strBaseName + "*" + objMaxReleaseMatch.Groups["FileExtension"].Value))
{
objCurrentLocalFileMatch = objRegExLocalFiles.Match(strFile);
if (objCurrentLocalFileMatch != null && !String.IsNullOrEmpty(objCurrentLocalFileMatch.Value))
Expand All @@ -390,7 +392,9 @@ private void downloadCore(String coreName, String coreURL, String coreDirectory,
{
if (!Directory.Exists(strDestinationDirectory) && !CreateDirectorySafe(strDestinationDirectory)) return;

strDestinationFile = Path.Combine(strDestinationDirectory, objMaxReleaseMatch.Groups["FileName"].Value);
strDestinationFile = objMaxReleaseMatch.Groups["FileName"].Value;
if (removeArcadePrefix && strDestinationFile.StartsWith("Arcade-")) strDestinationFile = strDestinationFile.Remove(0, 7);
strDestinationFile = Path.Combine(strDestinationDirectory, strDestinationFile);
writeStatusLabel_TS("Downloading " + coreName);
Application.DoEvents();
try
Expand All @@ -404,16 +408,16 @@ private void downloadCore(String coreName, String coreURL, String coreDirectory,
System.Threading.Thread.Sleep(intErrorPause);
return;
};
switch (objMaxReleaseMatch.Groups["BaseName"].Value)
switch (strBaseName)
{
case "MiSTer":
if (File.Exists(Path.Combine(coreDirectory, objMaxReleaseMatch.Groups["BaseName"].Value))) File.Delete(Path.Combine(coreDirectory, objMaxReleaseMatch.Groups["BaseName"].Value));
File.Move(strDestinationFile, Path.Combine(coreDirectory, objMaxReleaseMatch.Groups["BaseName"].Value));
if (File.Exists(Path.Combine(coreDirectory, strBaseName))) File.Delete(Path.Combine(coreDirectory, strBaseName));
File.Move(strDestinationFile, Path.Combine(coreDirectory, strBaseName));
createEmptyFile(strDestinationFile);
break;
case "menu":
if (File.Exists(Path.Combine(coreDirectory, objMaxReleaseMatch.Groups["BaseName"].Value + objMaxReleaseMatch.Groups["FileExtension"].Value))) File.Delete(Path.Combine(coreDirectory, objMaxReleaseMatch.Groups["BaseName"].Value + objMaxReleaseMatch.Groups["FileExtension"].Value));
File.Move(strDestinationFile, Path.Combine(coreDirectory, objMaxReleaseMatch.Groups["BaseName"].Value + objMaxReleaseMatch.Groups["FileExtension"].Value));
if (File.Exists(Path.Combine(coreDirectory, strBaseName + objMaxReleaseMatch.Groups["FileExtension"].Value))) File.Delete(Path.Combine(coreDirectory, strBaseName + objMaxReleaseMatch.Groups["FileExtension"].Value));
File.Move(strDestinationFile, Path.Combine(coreDirectory, strBaseName + objMaxReleaseMatch.Groups["FileExtension"].Value));
createEmptyFile(strDestinationFile);
break;
};
Expand Down Expand Up @@ -468,7 +472,7 @@ private void asyncDownloadExtras(System.Windows.Forms.TreeNodeCollection Nodes,
private void downoadExtra(String extraName, String extraURL, String extraFilters, String extraDirectory)
{
String strReleases;
Regex objRegExReleases = new Regex("href=\"(?<ExtraURL>[^\"]*/(?<ExtraFile>[^\"]*?(?:" + extraFilters.Replace(" ", "|") + ")))\".*?<td class=\"age\">.*?<time-ago datetime=\"(?<Year>\\d{4})-(?<Month>\\d{2})-(?<Day>\\d{2})T(?<Hour>\\d{2}):(?<Minute>\\d{2}):(?<Second>\\d{2})Z\">", RegexOptions.Singleline);
Regex objRegExReleases = new Regex("href=\"(?<ExtraURL>[^\"]*/(?<ExtraFile>[^\"]*?(?:" + extraFilters.Replace(" ", "|") + ")))\".*?<td class=\"age\">.*?<time-ago datetime=\"(?<Year>\\d{4})-(?<Month>\\d{2})-(?<Day>\\d{2})T(?<Hour>\\d{2}):(?<Minute>\\d{2}):(?<Second>\\d{2})Z\"", RegexOptions.Singleline);
String strLocalFileName;
DateTime dtmReleaseDateTimeUTC;

Expand Down Expand Up @@ -1084,6 +1088,16 @@ private String getControlText_TS(System.Windows.Forms.Control control)
return this.Invoke(new delegateGetControlText(getControlText), control).ToString();
}

private delegate bool delegateGetControlChecked(System.Windows.Forms.Control control);
private bool getControlChecked(System.Windows.Forms.Control control)
{
return ((System.Windows.Forms.CheckBox)control).Checked;
}
private bool getControlChecked_TS(System.Windows.Forms.Control control)
{
return (bool)this.Invoke(new delegateGetControlChecked(getControlChecked), control);
}

private void writeStatusLabel(String labelText)
{
toolStripStatusLabel1.Text = labelText;
Expand Down Expand Up @@ -1269,7 +1283,7 @@ private void btn1ClickSetup_Click(object sender, EventArgs e)
blnDownloadingCores = true;
blnDownloadingExtras = true;
blnRunningWizard = true;
asyncDownloadCores(treeViewCores.Nodes, cmbMiSTerDir.Text, Path.Combine(getControlText_TS(cmbMiSTerDir), strWorkDir));
asyncDownloadCores(treeViewCores.Nodes, cmbMiSTerDir.Text, Path.Combine(getControlText_TS(cmbMiSTerDir), strWorkDir), getControlChecked_TS(chkRemoveArcadePrefix));
}
else
{
Expand Down Expand Up @@ -1333,7 +1347,7 @@ private void btnDownloadCores_Click(object sender, EventArgs e)
createSDInstallerSemaphore(getControlText_TS(cmbMiSTerDir), Path.Combine(getControlText_TS(cmbMiSTerDir), strWorkDir));
writeStatusLabel("Downloading cores");
blnDownloadingCores = true;
asyncDownloadCores(treeViewCores.Nodes, cmbMiSTerDir.Text, Path.Combine(getControlText_TS(cmbMiSTerDir), strWorkDir));
asyncDownloadCores(treeViewCores.Nodes, cmbMiSTerDir.Text, Path.Combine(getControlText_TS(cmbMiSTerDir), strWorkDir), getControlChecked_TS(chkRemoveArcadePrefix));
}
else
{
Expand Down

0 comments on commit 9112163

Please sign in to comment.