Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add install and delete option #20

Closed
CiroMeiraLins opened this issue Aug 10, 2018 · 3 comments
Closed

Add install and delete option #20

CiroMeiraLins opened this issue Aug 10, 2018 · 3 comments

Comments

@CiroMeiraLins
Copy link

Add install and delete option

@Euphoreka7
Copy link

and "install and delete all" please

@ghost
Copy link

ghost commented Sep 11, 2018

diff --git a/include/mode/install_nsp_mode.hpp b/include/mode/install_nsp_mode.hpp
index fcdc415..04bcf92 100644
--- a/include/mode/install_nsp_mode.hpp
+++ b/include/mode/install_nsp_mode.hpp
@@ -12,6 +12,7 @@ namespace tin::ui
             std::string m_name;
             FsStorageId m_destStorageId = FsStorageId_SdCard;
             bool m_ignoreReqFirmVersion = false;
+            bool m_deleteAfterInstall = false;
 
         public:
             InstallNSPMode();
@@ -20,5 +21,6 @@ namespace tin::ui
             void OnNSPSelected();
             void OnDestinationSelected();
             void OnIgnoreReqFirmVersionSelected();
+            void OnDeleteAfterInstallSelected();
     };
diff --git a/source/mode/install_nsp_mode.cpp b/source/mode/install_nsp_mode.cpp
index 36efa5d..b64c907 100644
--- a/source/mode/install_nsp_mode.cpp
+++ b/source/mode/install_nsp_mode.cpp
@@ -102,6 +102,29 @@ namespace tin::ui
 
         auto optStr = prevView->GetSelectedOptionValue()->GetText();
         m_ignoreReqFirmVersion = (optStr == "Yes");
+
+        auto view = std::make_unique<tin::ui::ConsoleOptionsView>();
+        view->AddEntry("Delete file after install", tin::ui::ConsoleEntrySelectType::HEADING, nullptr);
+        view->AddEntry("", tin::ui::ConsoleEntrySelectType::NONE, nullptr);
+        view->AddEntry("No", tin::ui::ConsoleEntrySelectType::SELECT, std::bind(&InstallNSPMode::OnDeleteAfterInstallSelected, this));
+        view->AddEntry("Yes", tin::ui::ConsoleEntrySelectType::SELECT, std::bind(&InstallNSPMode::OnDeleteAfterInstallSelected, this));
+        manager.PushView(std::move(view));
+    }
+
+    void InstallNSPMode::OnDeleteAfterInstallSelected()
+    {
+        // Retrieve previous selection
+        tin::ui::ViewManager& manager = tin::ui::ViewManager::Instance();
+        ConsoleOptionsView* prevView;
+
+        if (!(prevView = dynamic_cast<ConsoleOptionsView*>(manager.GetCurrentView())))
+        {
+            throw std::runtime_error("Previous view must be a ConsoleOptionsView!");
+        }
+
+        auto optStr = prevView->GetSelectedOptionValue()->GetText();
+        m_deleteAfterInstall = (optStr == "Yes");
+
         std::vector<std::string> installList;
 
         if (m_name == "Install All")
@@ -151,6 +174,16 @@ namespace tin::ui
                 fprintf(stdout, "%s", e.what());
                 break;
             }
+
+            if (m_deleteAfterInstall)
+            {
+                FsFileSystem sdcard;
+                fsMountSdcard(&sdcard);
+                std::string nspPath = "/tinfoil/nsp/" + installList[i];
+                nspPath.reserve(FS_MAX_PATH);
+                fsFsDeleteFile(&sdcard, nspPath.c_str());
+                fsFsClose(&sdcard);
+            }
         }
 
         printf("Done!\n\nPress (B) to return.\n");

@lobofoots
Copy link

Sometimes the install blocks midway, there is an error message about firmware or fs mitm problem. Do not delete all if install stops half way.

XorTroll pushed a commit that referenced this issue Feb 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants