Skip to content

Commit

Permalink
Reduced size of original games, fixes, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ClusterM committed Oct 10, 2017
1 parent 115c6a4 commit 6af5165
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 158 deletions.
43 changes: 29 additions & 14 deletions FelLib/Fel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,27 +64,27 @@ public static bool DeviceExists(UInt16 vid, UInt16 pid)
var fel = new Fel();
try
{
fel.Open(vid, pid);
Debug.WriteLine("Device detection successful");
return true;
}
catch (Exception ex)
{
Debug.WriteLine("Device detection error: " + ex.Message + ex.StackTrace);
return false;
if (fel.Open(vid, pid))
{
Debug.WriteLine("Device detection successful");
return true;
} else
{
return false;
}
}
finally
{
fel.Close();
}
}

public void Open(UInt16 vid, UInt16 pid)
public bool Open(UInt16 vid, UInt16 pid)
{
this.vid = vid;
this.pid = pid;
Close();
Debug.WriteLine("Trying to open device...");
//Debug.WriteLine("Trying to open device...");
var devices = UsbDevice.AllDevices;
device = null;
foreach (UsbRegistry regDevice in devices)
Expand All @@ -95,7 +95,13 @@ public void Open(UInt16 vid, UInt16 pid)
break;
}
}
if (device == null) throw new FelException("Device with such VID and PID not found");
if (device == null)
{
#if VERY_DEBUG
Debug.WriteLine("Device with such VID and PID not found");
#endif
return false;
}

IUsbDevice wholeUsbDevice = device as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
Expand Down Expand Up @@ -135,12 +141,21 @@ public void Open(UInt16 vid, UInt16 pid)
}
}
if (inEndp != 0x82 || outEndp != 0x01)
throw new Exception("Uncorrect FEL device");
{
Debug.WriteLine("Uncorrect FEL device/mode");
return false;
}
epReader = device.OpenEndpointReader((ReadEndpointID)inEndp, 65536);
epWriter = device.OpenEndpointWriter((WriteEndpointID)outEndp);

Debug.WriteLine("Trying to verify device");
if (VerifyDevice().Board != 0x00166700) throw new FelException("Invalid board ID: " + VerifyDevice().Board);
if (VerifyDevice().Board != 0x00166700)
{
Debug.WriteLine("Invalid board ID: " + VerifyDevice().Board);
return false;
}

return true;
}
public void Close()
{
Expand Down Expand Up @@ -394,7 +409,7 @@ public void RunUbootCmd(string command, bool noreturn = false, OnFelProgress cal
{
Thread.Sleep(500);
callback?.Invoke(CurrentAction.RunningCommand, command);
}
}
int errorCount = 0;
while (true)
{
Expand Down
214 changes: 109 additions & 105 deletions MainForm.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.21.10")]
[assembly: AssemblyFileVersion("2.0.21.10")]
[assembly: AssemblyVersion("2.0.21.20")]
[assembly: AssemblyFileVersion("2.0.21.20")]
[assembly: NeutralResourcesLanguageAttribute("en-US")]
16 changes: 0 additions & 16 deletions WaitingFelForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@ public static bool WaitForDevice(UInt16 vid, UInt16 pid, IWin32Window owner)
return form.DialogResult == DialogResult.OK;
}

static bool DeviceExists(UInt16 vid, UInt16 pid)
{
try
{
using (var fel = new Fel())
{
fel.Open(vid, pid);
return true;
}
}
catch
{
return false;
}
}

private void timer_Tick(object sender, EventArgs e)
{
if (Fel.DeviceExists(vid, pid))
Expand Down
48 changes: 33 additions & 15 deletions WorkerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ DialogResult WaitForFelFromThread()
if (!File.Exists(ubootPath)) throw new FileNotFoundException(ubootPath + " not found");
fel.Fes1Bin = File.ReadAllBytes(fes1Path);
fel.UBootBin = File.ReadAllBytes(ubootPath);
fel.Open(vid, pid);
if (!fel.Open(vid, pid))
throw new FelException("Can't open device");
SetStatus(Resources.UploadingFes1);
fel.InitDram(true);
TaskbarProgress.SetState(this, TaskbarProgress.TaskbarStates.Normal);
Expand Down Expand Up @@ -774,6 +775,7 @@ public void UploadGames()
string gamesPath = NesMiniApplication.GamesCloverPath;
const string rootFsPath = "/var/lib/hakchi/rootfs";
const string installPath = "/var/lib/hakchi";
const string squashFsPath = "/var/lib/hakchi/squashfs";
int progress = 0;
int maxProgress = 400;
if (Games == null || Games.Count == 0)
Expand Down Expand Up @@ -854,6 +856,15 @@ public void UploadGames()
}

SetStatus(Resources.UploadingOriginalGames);
var squashFsMount = clovershell.ExecuteSimple($"mount | grep {squashFsPath}", 30000, false);
if (string.IsNullOrEmpty(squashFsMount))
{
clovershell.ExecuteSimple($"mkdir -p {squashFsPath} && mount /dev/mapper/root-crypt {squashFsPath}", 30000, true);
MessageBoxFromThread(this, "Seems like your are using old version of custom kernel. " +
"Please install latest version using \"Kernel->Flash custom kernel\" menu to make original games work.",
Resources.CustomKernel, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, false);
}

startProgress = progress;
foreach (var originalCode in originalGames.Keys)
{
Expand All @@ -862,23 +873,30 @@ public void UploadGames()
{
case MainForm.ConsoleType.NES:
case MainForm.ConsoleType.Famicom:
originalSyncCode = $"mkdir -p \"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/\" && " +
$"rsync -ac \"{gamesPath}/{originalCode}/\" \"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/\" && " +
$"sed -i -e 's/\\/usr\\/bin\\/clover-kachikachi/\\/bin\\/clover-kachikachi-wr/g' \"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/{originalCode}.desktop\"";
originalSyncCode =
$"src=\"{squashFsPath}{gamesPath}/{originalCode}\" && " +
$"dst=\"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/\" && " +
$"mkdir -p \"$dst\" && " +
$"ln -s \"$src/{originalCode}.png\" \"$dst\" && " +
$"ln -s \"$src/{originalCode}_small.png\" \"$dst\" && " +
$"ln -s \"$src/{originalCode}.nes\" \"$dst\" && " +
$"ln -s \"$src/autoplay/\" \"$dst/autoplay\" && " +
$"ln -s \"$src/pixelart/\" \"$dst/pixelart\" && " +
$"cp \"$src/{originalCode}.desktop\" \"$dst/{originalCode}.desktop\" && " +
$"sed -i -e 's/\\/usr\\/bin\\/clover-kachikachi/\\/bin\\/clover-kachikachi-wr/g' \"$dst/{originalCode}.desktop\"";
break;
case MainForm.ConsoleType.SNES:
case MainForm.ConsoleType.SuperFamicom:
originalSyncCode = $"mkdir -p \"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/\" && " +
$"rsync -ac \"{gamesPath}/{originalCode}/\" \"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/\" && " +
$"sed -i -e 's/\\/usr\\/bin\\/clover-canoe-shvc/\\/bin\\/clover-canoe-shvc-wr/g' \"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/{originalCode}.desktop\"";
/*
// With compression but very slow
originalSyncCode = $"mkdir -p \"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/\" && " +
$"rsync -ac \"{gamesPath}/{originalCode}/\" \"/tmp/{originalCode}/\" && " +
$"gzip \"/tmp/{originalCode}/{originalCode}.sfrom\" && " +
$"rsync -ac \"/tmp/{originalCode}/\" \"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/\" && " +
$"rm -rf \"/tmp/{originalCode}/\"";
*/
originalSyncCode =

This comment has been minimized.

Copy link
@DanTheMan827

DanTheMan827 Oct 10, 2017

Collaborator

@ClusterM Just a thought, why not move the install commands to external text files and read that into clovershell with some variables set before it runs (like src, dst, gamecode)

$"src=\"{squashFsPath}{gamesPath}/{originalCode}\" && " +
$"dst=\"{rootFsPath}{gamesPath}/{originalGames[originalCode]}/{originalCode}/\" && " +
$"mkdir -p \"$dst\" && " +
$"ln -s \"$src/{originalCode}.png\" \"$dst\" && " +
$"ln -s \"$src/{originalCode}_small.png\" \"$dst\" && " +
$"ln -s \"$src/{originalCode}.sfrom\" \"$dst\" && " +
$"ln -s \"$src/autoplay/\" \"$dst/autoplay\" && " +
$"cp \"$src/{originalCode}.desktop\" \"$dst/{originalCode}.desktop\" && " +
$"sed -i -e 's/\\/usr\\/bin\\/clover-canoe-shvc/\\/bin\\/clover-canoe-shvc-wr/g' \"$dst/{originalCode}.desktop\"";
break;
}
clovershell.ExecuteSimple(originalSyncCode, 30000, true);
Expand Down
4 changes: 2 additions & 2 deletions hakchi_gui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<PublisherName>Alexey %27Cluster%27 Avdyukhin</PublisherName>
<CreateWebPageOnPublish>true</CreateWebPageOnPublish>
<WebPage>index.html</WebPage>
<ApplicationRevision>10</ApplicationRevision>
<ApplicationVersion>2.0.21.10</ApplicationVersion>
<ApplicationRevision>20</ApplicationRevision>
<ApplicationVersion>2.0.21.20</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down
2 changes: 1 addition & 1 deletion user_mods/remove_thumbnails.hmod/install
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ echo nesjson: $nesjson
restore $nesjson
# sed is GNU util to modify file, this command replaces "enabled:true" to "enabled:false"
# Please note that we need to edit $rootfs$scnfile (writable file), not a just $scnfile (original read-only file)
sed -i -e 's/"enabled":true/"enabled":false/g' $rootfs$scnfile
sed -i -e 's/color":\[1,1,1,1\]/color":\[1,1,1,0\]/g' $rootfs$scnfile
# Same with nes.json file, most simple way is to replace coordinates sprite coords with zeros
# For NES Mini
sed -i -e 's/\[93,861,12,8\]/\[0,0,0,0\]/g' $rootfs$nesjson
Expand Down
3 changes: 0 additions & 3 deletions user_mods/remove_thumbnails.hmod/readme.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
=== No-thumbnails Hack ===

This module removes thumbnails at the bottom of the screen.

Known problems:
- Long startup time on SNES Classic Mini for unknown reason

0 comments on commit 6af5165

Please sign in to comment.