Skip to content

Commit

Permalink
0.7.3 - 9.0.1 support
Browse files Browse the repository at this point in the history
XorTroll committed Oct 2, 2019
1 parent 0d0155c commit 76c8f46
Showing 12 changed files with 89 additions and 34 deletions.
Binary file modified Goldleaf/Icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Goldleaf/Include/Types.hpp
Original file line number Diff line number Diff line change
@@ -83,6 +83,7 @@ struct Version
};

static const std::string GoldleafDir = "switch/Goldleaf";
static const std::string TempGoldleafUpdateNro = "sdmc:/" + GoldleafDir + "/UpdateTemp.nro";

ExecutableMode GetExecutableMode();
LaunchMode GetLaunchMode();
2 changes: 2 additions & 0 deletions Goldleaf/Include/fs/fs_Common.hpp
Original file line number Diff line number Diff line change
@@ -64,6 +64,8 @@ namespace fs
void CopyDirectoryProgress(pu::String Dir, pu::String NewDir, std::function<void(double Done, double Total)> Callback);
void DeleteFile(pu::String Path);
void DeleteDirectory(pu::String Path);
void RenameFile(pu::String Old, pu::String New);
void RenameDirectory(pu::String Old, pu::String New);
bool IsFileBinary(pu::String Path);
void WriteFile(pu::String Path, std::vector<u8> Data);
u64 GetFileSize(pu::String Path);
10 changes: 9 additions & 1 deletion Goldleaf/Include/hos/hos_Content.hpp
Original file line number Diff line number Diff line change
@@ -29,9 +29,17 @@

namespace hos
{
struct PendingUpdateVersion
{
u32 Major;
u32 Minor;
u32 Micro;
};

pu::String ContentIdAsString(const NcmNcaId &ContentId);
NcmNcaId StringAsContentId(pu::String ContentId);

SetSysFirmwareVersion GetPendingUpdateInfo();
bool GetPendingUpdateInfo(PendingUpdateVersion *out);
SetSysFirmwareVersion ConvertPendingUpdateVersion(PendingUpdateVersion ver);
void CleanPendingUpdate();
}
2 changes: 1 addition & 1 deletion Goldleaf/Makefile
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ include $(DEVKITPRO)/libnx/switch_rules

VER_MAJOR := 0
VER_MINOR := 7
VER_MICRO := 2
VER_MICRO := 3

APP_TITLE := Goldleaf
APP_AUTHOR := XorTroll
Binary file modified Goldleaf/RomFs/MenuBanner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion Goldleaf/Source/Main.cpp
Original file line number Diff line number Diff line change
@@ -90,13 +90,21 @@ namespace ui
extern MainApplication::Ref mainapp;
}

int main()
bool gupdated = false;

int main(int argc, char **argv)
{
Initialize();

ui::mainapp = ui::MainApplication::New();
ui::mainapp->ShowWithFadeIn();

if(gupdated)
{
romfsExit();
fs::DeleteFile(argv[0]);
fs::RenameFile(TempGoldleafUpdateNro, argv[0]);
}
Finalize();
return 0;
}
12 changes: 12 additions & 0 deletions Goldleaf/Source/fs/fs_Common.cpp
Original file line number Diff line number Diff line change
@@ -121,6 +121,18 @@ namespace fs
if(exp != NULL) exp->DeleteDirectory(Path);
}

void RenameFile(pu::String Old, pu::String New)
{
auto exp = GetExplorerForPath(Old);
if(exp != NULL) exp->RenameFile(Old, New);
}

void RenameDirectory(pu::String Old, pu::String New)
{
auto exp = GetExplorerForPath(Old);
if(exp != NULL) exp->RenameDirectory(Old, New);
}

bool IsFileBinary(pu::String Path)
{
if(GetFileSize(Path) == 0) return true;
25 changes: 10 additions & 15 deletions Goldleaf/Source/hos/hos_Common.cpp
Original file line number Diff line number Diff line change
@@ -191,20 +191,15 @@ namespace hos

u8 ComputeSystemKeyGeneration()
{
u8 masterkey = 0;

MKEY_SET_IF(VERSION_BETWEEN(1,0,0,2,3,0), 0)
MKEY_SET_IF(VERSION_EXACT(3,0,0), 1)
MKEY_SET_IF(VERSION_BETWEEN(3,0,1,3,0,2), 2)
MKEY_SET_IF(VERSION_BETWEEN(4,0,0,4,1,0), 3)
MKEY_SET_IF(VERSION_BETWEEN(5,0,0,5,1,0), 4)
MKEY_SET_IF(VERSION_BETWEEN(6,0,0,6,1,0), 5)
MKEY_SET_IF(VERSION_EXACT(6,2,0), 6)
MKEY_SET_IF(VERSION_BETWEEN(7,0,0,8,0,1), 7)
MKEY_SET_IF(VERSION_EXACT(8,1,0), 8)
MKEY_SET_IF(VERSION_EXACT(9,0,0), 9)

// KeyGen = MasterKey + 1!
return masterkey + 1;
FsStorage boot0;
auto rc = fsOpenBisStorage(&boot0, FsBisStorageId_Boot0);
if(R_SUCCEEDED(rc))
{
u32 keygen_ver = 0;
fsStorageRead(&boot0, 0x2330, &keygen_ver, sizeof(u32));
fsStorageClose(&boot0);
return (u8)keygen_ver;
}
return 0;
}
}
39 changes: 33 additions & 6 deletions Goldleaf/Source/hos/hos_Content.cpp
Original file line number Diff line number Diff line change
@@ -22,6 +22,13 @@
#include <hos/hos_Content.hpp>
#include <fs/fs_Explorer.hpp>

#include <ui/ui_MainApplication.hpp>

namespace ui
{
extern MainApplication::Ref mainapp;
}

namespace hos
{
pu::String ContentIdAsString(const NcmNcaId &NCAId)
@@ -45,24 +52,44 @@ namespace hos
return nid;
}

SetSysFirmwareVersion GetPendingUpdateInfo()
bool GetPendingUpdateInfo(PendingUpdateVersion *out)
{
auto sys = fs::GetNANDSystemExplorer();
auto ncas = sys->GetFiles("Contents/placehld");
SetSysFirmwareVersion fwver = {0};
bool found = false;
for(auto &nca: ncas)
{
std::string path = "@SystemContent://placehld/" + nca.AsUTF8();
path.reserve(FS_MAX_PATH);
FsFileSystem ncafs;
auto rc = fsOpenFileSystemWithId(&ncafs, 0x0100000000000809, FsFileSystemType_ContentData, path.c_str());
auto rc = fsOpenFileSystemWithId(&ncafs, 0, FsFileSystemType_ContentMeta, path.c_str());
if(R_SUCCEEDED(rc))
{
fs::FileSystemExplorer fwfs("gncafwver", "...", &ncafs);
fwfs.ReadFileBlock("file", 0, sizeof(fwver), (u8*)&fwver);
break;
fs::FileSystemExplorer fwfs("gpendupd", "...", &ncafs);
auto fs = fwfs.GetContents();
for(auto &f: fs)
{
u32 rawver = 0;
fwfs.ReadFileBlock(f, 8, sizeof(u32), (u8*)&rawver);
out->Major = (u8)((rawver >> 26) & 0x3f);
out->Minor = (u8)((rawver >> 20) & 0x3f);
out->Micro = (u8)((rawver >> 16) & 0x3f);
found = true;
break; // We just want to read the first CNMT NCA we succeed mounting :P
}
if(found) break;
}
}
return found;
}

SetSysFirmwareVersion ConvertPendingUpdateVersion(PendingUpdateVersion ver)
{
SetSysFirmwareVersion fwver = {};
fwver.major = ver.Major;
fwver.minor = ver.Minor;
fwver.micro = ver.Micro;
sprintf(fwver.display_version, "%d.%d.%d", ver.Major, ver.Minor, ver.Micro);
return fwver;
}

14 changes: 7 additions & 7 deletions Goldleaf/Source/ui/ui_SettingsLayout.cpp
Original file line number Diff line number Diff line change
@@ -116,14 +116,14 @@ namespace ui
pu::String msg = set::GetDictionaryEntry(362) + ":\n";
msg += pu::String("\n" + set::GetDictionaryEntry(363) + ": ") + fwver.display_version + " (" + fwver.display_title + ")";
msg += pu::String("\n" + set::GetDictionaryEntry(364) + ": '") + fwver.version_hash + "'";
msg += pu::String("\n" + set::GetDictionaryEntry(95) + " ") + std::to_string(hos::ComputeSystemKeyGeneration());
msg += "\n\n" + set::GetDictionaryEntry(365) + ":\n";
auto basefw = fwver;
fwver = hos::GetPendingUpdateInfo();
bool pendingpresent = ((fwver.major != 0) && (fwver.display_title[0] != '\0'));
hos::PendingUpdateVersion pupd = {};
bool pendingpresent = hos::GetPendingUpdateInfo(&pupd);
auto pendfwver = hos::ConvertPendingUpdateVersion(pupd);
if(pendingpresent)
{
msg += pu::String("\n" + set::GetDictionaryEntry(363) + ": ") + fwver.display_version + " (" + fwver.display_title + ")";
msg += pu::String("\n" + set::GetDictionaryEntry(364) + ": '") + fwver.version_hash + "'";
msg += pu::String("\n" + set::GetDictionaryEntry(363) + ": ") + std::to_string(pupd.Major) + "." + std::to_string(pupd.Minor) + "." + std::to_string(pupd.Micro);
msg += "\n" + set::GetDictionaryEntry(366);
}
else msg += "\n" + set::GetDictionaryEntry(367);
@@ -137,7 +137,7 @@ namespace ui

auto sopt = mainapp->CreateShowDialog(set::GetDictionaryEntry(360), msg, opts, false);
if(sopt == 0) return;
else if(sopt == 1) this->HandleUpdate("Contents/registered", basefw);
else if(sopt == 1) this->HandleUpdate("Contents/registered", fwver);
else if(sopt == 2)
{
auto sopt = mainapp->CreateShowDialog(set::GetDictionaryEntry(371), set::GetDictionaryEntry(372) + "\n" + set::GetDictionaryEntry(373), { set::GetDictionaryEntry(111), set::GetDictionaryEntry(18) }, true);
@@ -147,7 +147,7 @@ namespace ui
mainapp->ShowNotification(set::GetDictionaryEntry(374));
}
}
else if(sopt == 3) this->HandleUpdate("Contents/placehld", fwver);
else if(sopt == 3) this->HandleUpdate("Contents/placehld", pendfwver);
}

void SettingsLayout::optsMemory_Click()
8 changes: 5 additions & 3 deletions Goldleaf/Source/ui/ui_UpdateLayout.cpp
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@
#include <ui/ui_MainApplication.hpp>

extern set::Settings gsets;
extern bool gupdated;

namespace ui
{
@@ -41,7 +42,7 @@ namespace ui

void UpdateLayout::StartUpdateSearch()
{
if(!net::HasConnection())
if((!net::HasConnection()) || gupdated)
{
mainapp->CreateShowDialog(set::GetDictionaryEntry(284), set::GetDictionaryEntry(304), { set::GetDictionaryEntry(234) }, true);
mainapp->UnloadMenuData();
@@ -69,16 +70,17 @@ namespace ui
{
std::string baseurl = "https://github.com/XorTroll/Goldleaf/releases/download/" + latestid + "/Goldleaf";
fs::CreateDirectory("sdmc:/switch/Goldleaf");
fs::DeleteFile("sdmc:/switch/Goldleaf/Goldleaf.nro");
fs::DeleteFile(TempGoldleafUpdateNro);
this->infoText->SetText(set::GetDictionaryEntry(309));
mainapp->CallForRender();
this->downloadBar->SetVisible(true);
net::RetrieveToFile(baseurl + ".nro", "sdmc:/switch/Goldleaf/Goldleaf.nro", [&](double Done, double Total)
net::RetrieveToFile(baseurl + ".nro", TempGoldleafUpdateNro, [&](double Done, double Total)
{
this->downloadBar->SetMaxValue(Total);
this->downloadBar->SetProgress(Done);
mainapp->CallForRender();
});
if(fs::IsFile(TempGoldleafUpdateNro)) gupdated = true;
this->downloadBar->SetVisible(false);
mainapp->CallForRender();
sopt = mainapp->CreateShowDialog(set::GetDictionaryEntry(284), set::GetDictionaryEntry(310), { set::GetDictionaryEntry(111), set::GetDictionaryEntry(18) }, true);

0 comments on commit 76c8f46

Please sign in to comment.