Exemple #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;
            }
        }
Exemple #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;
            }
        }
        public ResultOrError <string> ChangeDirectory(string path)
        {
            string newPath = ResolvePath(path);

            try
            {
                shell.ExecuteSimple("cd \"" + newPath + "\"", 1000, true);
                currentPath = newPath;
            }
            catch (Exception ex)
            {
                return(MakeError <string>(ex.Message));
            }
            return(MakeResult <string>(newPath));
        }