Skip to content

Commit

Permalink
Few enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardoGiordano committed Dec 27, 2018
1 parent 9252a24 commit 8a01c51
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 56 deletions.
Binary file added 3ds/assets/romfs/PKSM.smdh
Binary file not shown.
3 changes: 3 additions & 0 deletions 3ds/include/smdh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define SMDH_HPP

#include <3ds.h>
#include <fstream>
#include <string>

typedef struct {
u32 magic;
Expand Down Expand Up @@ -62,5 +64,6 @@ typedef struct {
} smdh_s;

smdh_s* loadSMDH(u32 low, u32 high, u8 media);
smdh_s* loadSMDH(const std::string& path);

#endif
2 changes: 2 additions & 0 deletions 3ds/include/title.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ extern "C" {
#include "sha256.h"
}

#define TID_PKSM 0x000400000EC10000

class Title
{
public:
Expand Down
17 changes: 15 additions & 2 deletions 3ds/source/smdh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

#include "smdh.hpp"

smdh_s *loadSMDH(u32 low, u32 high, u8 media)
smdh_s* loadSMDH(u32 low, u32 high, u8 media)
{
Handle fileHandle;

u32 archPath[] = {low, high, media, 0x0};
static const u32 filePath[] = {0x0, 0x0, 0x2, 0x6E6F6369, 0x0};
smdh_s *smdh = new smdh_s;
smdh_s* smdh = new smdh_s;

FS_Path binArchPath = {PATH_BINARY, 0x10, archPath};
FS_Path binFilePath = {PATH_BINARY, 0x14, filePath};
Expand All @@ -51,4 +51,17 @@ smdh_s *loadSMDH(u32 low, u32 high, u8 media)

FSFILE_Close(fileHandle);
return smdh;
}

smdh_s* loadSMDH(const std::string& path)
{
std::ifstream is(path, std::ios::binary);
if (is)
{
smdh_s* smdh = new smdh_s;
is.read((char*)smdh, sizeof(smdh_s));
is.close();
return smdh;
}
return NULL;
}
32 changes: 31 additions & 1 deletion 3ds/source/title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ bool Title::load(u64 _id, FS_MediaType _media, FS_CardType _card)

if (mCard == CARD_CTR)
{
smdh_s *smdh = loadSMDH(lowId(), highId(), mMedia);
smdh_s* smdh;
if (mId == TID_PKSM)
{
smdh = loadSMDH("romfs:/PKSM.smdh");
}
else
{
smdh = loadSMDH(lowId(), highId(), mMedia);
}
if (smdh == NULL)
{
return false;
Expand Down Expand Up @@ -566,6 +574,28 @@ void loadTitles(bool forceRefresh)
}
}
}

// always check for PKSM's extdata archive
bool isPKSMIdAlreadyHere = false;
for (u32 i = 0; i < count; i++)
{
if (ids[i] == TID_PKSM)
{
isPKSMIdAlreadyHere = true;
break;
}
}
if (!isPKSMIdAlreadyHere)
{
Title title;
if (title.load(TID_PKSM, MEDIATYPE_SD, CARD_CTR))
{
if (title.accessibleExtdata())
{
titleExtdatas.push_back(title);
}
}
}

std::sort(titleSaves.begin(), titleSaves.end(), [](Title& l, Title& r) {
return l.shortDescription() < r.shortDescription() &&
Expand Down
30 changes: 0 additions & 30 deletions issue_template.md

This file was deleted.

2 changes: 0 additions & 2 deletions switch/include/pksmbridge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
*/

#include <switch.h>
#include <fcntl.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
Expand Down
31 changes: 11 additions & 20 deletions switch/source/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,34 +465,25 @@ void Gui::updateButtons(void)
}
else if (backupScrollEnabled)
{
if (getPKSMBridgeFlag())
{
buttonBackup->text("Send \ue004");
buttonRestore->text("Receive \ue005");
}
else
{
buttonBackup->text("Backup \ue004");
buttonRestore->text("Restore \ue005");
}
buttonBackup->setColors(theme().c6, theme().c0);
buttonRestore->setColors(theme().c6, theme().c0);
}
else
{
if (getPKSMBridgeFlag())
{
buttonBackup->text("Send \ue004");
buttonRestore->text("Receive \ue005");
}
else
{
buttonBackup->text("Backup \ue004");
buttonRestore->text("Restore \ue005");
}
buttonBackup->setColors(theme().c6, theme().c5);
buttonRestore->setColors(theme().c6, theme().c5);
}

if (getPKSMBridgeFlag())
{
buttonBackup->text("Send \ue004");
buttonRestore->text("Receive \ue005");
}
else
{
buttonBackup->text("Backup \ue004");
buttonRestore->text("Restore \ue005");
}
}

void Gui::updateSelector(void)
Expand Down
2 changes: 1 addition & 1 deletion switch/source/pksmbridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void recvFromPKSMBridge(size_t index, u128 uid)
getTitle(title, uid, index);
std::string srcPath = title.fullPath(cellIndex) + "/";
std::ofstream save(srcPath + "savedata.bin", std::ios::binary);
char* data = new char[size];
char* data = new char[size]();

size_t total = 0;
size_t chunk = 1024;
Expand Down

0 comments on commit 8a01c51

Please sign in to comment.