예제 #1
0
        public static void Shell_OnConnected(ISystemShell caller)
        {
            // set calling shell as current used shell and disable others
            Shell = caller;
            shells.ForEach(shell => { if (shell != caller)
                                      {
                                          shell.Enabled = false;
                                      }
                           });
            try
            {
                Connected = Shell.IsOnline;
                if (!Shell.IsOnline)
                {
                    throw new IOException("Shell connection should be online!");
                }

                MinimalMemboot = Shell.Execute("source /hakchi/config; [ \"$cf_memboot\" = \"y\" ]") == 0;

                // detect unique id
                UniqueID = Shell.ExecuteSimple("echo \"`devmem 0x01C23800``devmem 0x01C23804``devmem 0x01C23808``devmem 0x01C2380C`\"").Trim().Replace("0x", "");
                Debug.WriteLine($"Detected device unique ID: {UniqueID}");

                // execution stops here for a minimal memboot
                if (!MinimalMemboot)
                {
                    // detect running/mounted firmware
                    string board  = Shell.ExecuteSimple("cat /etc/clover/boardtype", 3000, true);
                    string region = Shell.ExecuteSimple("cat /etc/clover/REGION", 3000, true);
                    DetectedConsoleType = translateConsoleType(board, region);
                    if (DetectedConsoleType == ConsoleType.Unknown)
                    {
                        throw new IOException("Unable to determine mounted firmware");
                    }
                    var customFirmwareLoaded = Shell.ExecuteSimple("hakchi currentFirmware");
                    CustomFirmwareLoaded = customFirmwareLoaded != "_nand_";
                    Debug.WriteLine(string.Format("Detected mounted board: {0}, region: {1}, firmware: {2}", board, region, customFirmwareLoaded));

                    // detect running versions
                    var versions = Shell.ExecuteSimple("source /var/version && echo \"$bootVersion $kernelVersion $hakchiVersion\"", 500, true).Split(' ');
                    BootVersion   = versions[0];
                    KernelVersion = versions[1];
                    ScriptVersion = versions[2];
                    Debug.WriteLine($"Detected versions: boot {BootVersion}, kernel {KernelVersion}, script {ScriptVersion}");
                    CanInteract = !SystemRequiresReflash() && !SystemRequiresRootfsUpdate();

                    // only do more interaction if safe to do so
                    if (CanInteract)
                    {
                        // detect basic paths
                        RemoteGameSyncPath = Shell.ExecuteSimple("hakchi findGameSyncStorage", 2000, true).Trim();
                        SystemCode         = Shell.ExecuteSimple("hakchi eval 'echo \"$sftype-$sfregion\"'", 2000, true).Trim();
                        OriginalGamesPath  = Shell.ExecuteSimple("hakchi get gamepath", 2000, true).Trim();
                        RootFsPath         = Shell.ExecuteSimple("hakchi get rootfs", 2000, true).Trim();
                        SquashFsPath       = Shell.ExecuteSimple("hakchi get squashfs", 2000, true).Trim();

                        // load config
                        ConfigIni.SetConfigDictionary(LoadConfig());

                        // calculate stats
                        MemoryStats.Refresh();
                    }
                }

                // chain to other OnConnected events
                OnConnected(caller);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
                CanInteract    = false;
                MinimalMemboot = false;
            }
        }
예제 #2
0
        public static void Shell_OnConnected(ISystemShell caller)
        {
            // set calling shell as current used shell and disable others
            Shell = caller;
            shells.ForEach(shell => { if (shell != caller)
                                      {
                                          shell.Enabled = false;
                                      }
                           });
            try
            {
                if (!Shell.IsOnline)
                {
                    throw new IOException("Shell connection should be online!");
                }
                DetectedConsoleType = ConsoleType.Unknown;

                MinimalMemboot = Shell.Execute("source /hakchi/config; [ \"$cf_memboot\" = \"y\" ]") == 0;
                UniqueID       = Shell.ExecuteSimple("hakchi hwid").Replace(" ", "");
                Trace.WriteLine($"Detected device unique ID: {UniqueID}");

                // execution stops here for a minimal memboot
                if (!MinimalMemboot)
                {
                    var versionExists = Shell.ExecuteSimple("[ -f /var/version ] && echo \"yes\"", 2000, true) == "yes";
                    if (versionExists)
                    {
                        var versions = Shell.ExecuteSimple("source /var/version && echo \"$bootVersion $kernelVersion $hakchiVersion\"", 2000, true).Split(' ');
                        RawBootVersion   = versions[0];
                        RawKernelVersion = versions[1];
                        RawScriptVersion = versions[2];
                        Trace.WriteLine($"Detected versions: boot {RawBootVersion}, kernel {RawKernelVersion}, script {RawScriptVersion}");

                        CanInteract = !SystemRequiresReflash() && !SystemRequiresRootfsUpdate();
                    }
                    else
                    {
                        RawBootVersion   = "1.0.0";
                        RawKernelVersion = "3.4.112-00";
                        RawScriptVersion = "v1.0.0-000";
                        Trace.WriteLine("Detected versions: severely outdated!");

                        CanInteract = false;
                    }

                    if (CanInteract)
                    {
                        // disable sync on legacy clovershell
                        CanSync = !(caller is ClovershellConnection);

                        // detect console firmware/type
                        SystemCode = Shell.ExecuteSimple("hakchi eval 'echo \"$sftype-$sfregion\"'", 2000, true).Trim();
                        if (SystemCodeToConsoleType.ContainsKey(SystemCode))
                        {
                            DetectedConsoleType = SystemCodeToConsoleType[SystemCode];
                        }
                        CustomFirmwareLoaded = Shell.ExecuteSimple("hakchi currentFirmware", 2000, true) != "_nand_";

                        // detect basic paths
                        RemoteGameSyncPath = Shell.ExecuteSimple("hakchi findGameSyncStorage", 2000, true).Trim();
                        OriginalGamesPath  = Shell.ExecuteSimple("hakchi get gamepath", 2000, true).Trim();
                        RootFsPath         = Shell.ExecuteSimple("hakchi get rootfs", 2000, true).Trim();
                        SquashFsPath       = Shell.ExecuteSimple("hakchi get squashfs", 2000, true).Trim();

                        // load config
                        ConfigIni.SetConfigDictionary(LoadConfig());

                        // calculate stats
                        MemoryStats.Refresh();
                    }
                }

                // chain to other OnConnected events
                Connected = Shell.IsOnline;
                OnConnected(caller);
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message + ex.StackTrace);
                CanInteract    = false;
                MinimalMemboot = false;
            }
        }
예제 #3
0
        public static void Clovershell_OnConnected()
        {
            // clear up values
            Clovershell_OnDisconnected();
            try
            {
                var Clovershell = MainForm.Clovershell;
                if (!Clovershell.IsOnline)
                {
                    throw new IOException("Clovershell connection unexpectedly offline");
                }

                MinimalMemboot = Clovershell.Execute("stat /generalmemboot.flag &>/dev/null") == 0;

                // detect unique id
                UniqueID = Clovershell.ExecuteSimple("echo \"`devmem 0x01C23800``devmem 0x01C23804``devmem 0x01C23808``devmem 0x01C2380C`\"").Trim().Replace("0x", "");
                Debug.WriteLine($"Detected device unique ID: {UniqueID}");

                if (MinimalMemboot)
                {
                    return;
                }

                // detect running/mounted firmware
                string board  = Clovershell.ExecuteSimple("cat /etc/clover/boardtype", 3000, true);
                string region = Clovershell.ExecuteSimple("cat /etc/clover/REGION", 3000, true);
                Debug.WriteLine(string.Format("Detected mounted board: {0}", board));
                Debug.WriteLine(string.Format("Detected mounted region: {0}", region));
                DetectedMountedConsoleType = translateConsoleType(board, region);
                if (DetectedMountedConsoleType == MainForm.ConsoleType.Unknown)
                {
                    throw new IOException("Unable to determine mounted firmware");
                }

                // detect running versions
                var versions = MainForm.Clovershell.ExecuteSimple("source /var/version && echo \"$bootVersion $kernelVersion $hakchiVersion\"", 500, true).Split(' ');
                BootVersion   = versions[0];
                KernelVersion = versions[1];
                ScriptVersion = versions[2];
                CanInteract   = !SystemRequiresReflash() && !SystemRequiresRootfsUpdate();

                // only do more interaction if safe to do so
                if (CanInteract)
                {
                    // detect root firmware
                    var customFirmwareLoaded = Clovershell.ExecuteSimple("hakchi currentFirmware") != "_nand_";
                    if (customFirmwareLoaded)
                    {
                        Clovershell.ExecuteSimple("cryptsetup open /dev/nandb root-crypt --readonly --type plain --cipher aes-xts-plain --key-file /etc/key-file", 3000);
                        Clovershell.ExecuteSimple("mkdir -p /var/squashfs-original", 3000, true);
                        Clovershell.ExecuteSimple("mount /dev/mapper/root-crypt /var/squashfs-original", 3000, true);
                        board  = Clovershell.ExecuteSimple("cat /var/squashfs-original/etc/clover/boardtype", 3000, true);
                        region = Clovershell.ExecuteSimple("cat /var/squashfs-original/etc/clover/REGION", 3000, true);
                        Debug.WriteLine(string.Format("Detected system board: {0}", board));
                        Debug.WriteLine(string.Format("Detected system region: {0}", region));
                        Clovershell.ExecuteSimple("umount /var/squashfs-original", 3000, true);
                        Clovershell.ExecuteSimple("rm -rf /var/squashfs-original", 3000, true);
                        Clovershell.ExecuteSimple("cryptsetup close root-crypt", 3000, true);
                    }
                    DetectedConsoleType = translateConsoleType(board, region);

                    // detect basic paths
                    RemoteGameSyncPath = MainForm.Clovershell.ExecuteSimple("hakchi findGameSyncStorage", 2000, true).Trim();
                    SystemCode         = MainForm.Clovershell.ExecuteSimple("hakchi eval 'echo \"$sftype-$sfregion\"'", 2000, true).Trim();

                    // load config
                    ConfigIni.SetConfigDictionary(LoadConfig());
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
                CanInteract    = false;
                MinimalMemboot = false;
            }
        }