Refactor code

This commit is contained in:
BernardoGiordano 2019-05-06 22:51:09 +02:00
parent 46d659795a
commit 13c0cfe9be
85 changed files with 4498 additions and 5323 deletions

90
.clang-format Normal file
View file

@ -0,0 +1,90 @@
---
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
#AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: false
# SplitEmptyFunction: true
# SplitEmptyRecord: true
# SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Stroustrup
BreakBeforeTernaryOperators: true
#BreakConstructorInitializers: AfterColon
BreakConstructorInitializersBeforeComma: false
BreakStringLiterals: true
ColumnLimit: 150
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros: [ foreach ]
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '$'
IndentCaseLabels: true
IndentWidth: 4
IndentWrappedFunctionNames: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
...

View file

@ -42,9 +42,11 @@ VERSION_MICRO := 0
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
OUTDIR := out
BUILD := build
SOURCES := source ../common ../3rd-party/sha256
FORMATSOURCES := source ../common
SOURCES := $(FORMATSOURCES) ../3rd-party/sha256
DATA := data
INCLUDES := include ../common ../3rd-party/json ../3rd-party/sha256
FORMATINCLUDES := include ../common
INCLUDES := $(FORMATINCLUDES) ../3rd-party/json ../3rd-party/sha256
GRAPHICS := assets/gfx
ROMFS := assets/romfs
GFXBUILD := $(ROMFS)/gfx
@ -180,7 +182,7 @@ ifneq ($(ROMFS),)
export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
endif
.PHONY: all clean
.PHONY: all clean format
#---------------------------------------------------------------------------------
all:
@ -199,7 +201,9 @@ endif
clean:
@echo clean ...
@rm -fr $(BUILD) $(OUTDIR)
#---------------------------------------------------------------------------------
format:
clang-format -i -style=file $(foreach dir,$(FORMATSOURCES),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cpp)) $(foreach dir,$(FORMATINCLUDES),$(wildcard $(dir)/*.h) $(wildcard $(dir)/*.hpp))
#---------------------------------------------------------------------------------
else

View file

@ -1,38 +1,37 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef KEYBOARDMANAGER_HPP
#define KEYBOARDMANAGER_HPP
#include "util.hpp"
#include <3ds.h>
#include <string>
#include "util.hpp"
class KeyboardManager
{
class KeyboardManager {
public:
static KeyboardManager& get(void)
{
@ -50,7 +49,7 @@ public:
private:
KeyboardManager(void);
virtual ~KeyboardManager(void) { }
virtual ~KeyboardManager(void) {}
SwkbdState mSwkbd;
};

View file

@ -1,55 +1,51 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef ARCHIVE_HPP
#define ARCHIVE_HPP
#include <3ds.h>
#include "fsstream.hpp"
#include "util.hpp"
#include <3ds.h>
typedef enum {
MODE_SAVE,
MODE_EXTDATA
} Mode_t;
typedef enum { MODE_SAVE, MODE_EXTDATA } Mode_t;
namespace Archive
{
Result init(void);
void exit(void);
Mode_t mode(void);
void mode(Mode_t v);
namespace Archive {
Result init(void);
void exit(void);
Mode_t mode(void);
void mode(Mode_t v);
FS_Archive sdmc(void);
Result save(FS_Archive* archive, FS_MediaType mediatype, u32 lowid, u32 highid);
Result extdata(FS_Archive* archive, u32 extdata);
bool accessible(FS_MediaType mediatype, u32 lowid, u32 highid); // save
bool accessible(u32 extdata); // extdata
bool setPlayCoins(void);
Result save(FS_Archive* archive, FS_MediaType mediatype, u32 lowid, u32 highid);
Result extdata(FS_Archive* archive, u32 extdata);
bool accessible(FS_MediaType mediatype, u32 lowid, u32 highid); // save
bool accessible(u32 extdata); // extdata
bool setPlayCoins(void);
}
#endif

View file

@ -1,44 +1,43 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef CHEATMANAGER_HPP
#define CHEATMANAGER_HPP
#include <3ds.h>
#include <sys/stat.h>
#include <stdio.h>
#include <bzlib.h>
#include "json.hpp"
#include "gui.hpp"
#include "json.hpp"
#include "main.hpp"
#include "scrollable.hpp"
#include "thread.hpp"
#include <3ds.h>
#include <bzlib.h>
#include <stdio.h>
#include <sys/stat.h>
namespace CheatManager
{
namespace CheatManager {
void init(void);
void exit(void);
bool loaded(void);

View file

@ -1,53 +1,49 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef CLICKABLE_HPP
#define CLICKABLE_HPP
#include "colors.hpp"
#include "iclickable.hpp"
#include "main.hpp"
#include <citro2d.h>
#include <string>
#include "iclickable.hpp"
#include "colors.hpp"
#include "main.hpp"
class Clickable : public IClickable<u32>
{
class Clickable : public IClickable<u32> {
public:
Clickable(int x, int y, u16 w, u16 h, u32 colorBg, u32 colorText, std::string message, bool centered)
: IClickable(x, y, w, h, colorBg, colorText, message, centered)
: IClickable(x, y, w, h, colorBg, colorText, message, centered)
{
mTextBuf = C2D_TextBufNew(64);
C2D_TextParse(&mC2dText, mTextBuf, message.c_str());
C2D_TextOptimize(&mC2dText);
}
virtual ~Clickable(void)
{
C2D_TextBufDelete(mTextBuf);
}
virtual ~Clickable(void) { C2D_TextBufDelete(mTextBuf); }
void draw(float size, u32 overlay) override;
void drawOutline(u32 color) override;
@ -56,7 +52,7 @@ public:
void c2dText(const std::string& text);
protected:
C2D_Text mC2dText;
C2D_Text mC2dText;
C2D_TextBuf mTextBuf;
};

View file

@ -1,43 +1,42 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef CONFIGHANDLER_HPP
#define CONFIGHANDLER_HPP
#include "io.hpp"
#include "json.hpp"
#include "util.hpp"
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "json.hpp"
#include "io.hpp"
#include "util.hpp"
#define CONFIG_VERSION 2
class Configuration
{
class Configuration {
public:
static Configuration& getInstance(void)
{
@ -53,7 +52,7 @@ public:
private:
Configuration(void);
~Configuration(void) { };
~Configuration(void){};
void store(void);
nlohmann::json loadJson(const std::string& path);

View file

@ -1,54 +1,52 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef DIRECTORY_HPP
#define DIRECTORY_HPP
#include "util.hpp"
#include <3ds.h>
#include <string>
#include <vector>
#include "util.hpp"
class Directory
{
class Directory {
public:
Directory(FS_Archive archive, const std::u16string& root);
~Directory(void) { };
~Directory(void){};
Result error(void);
Result error(void);
std::u16string entry(size_t index);
bool folder(size_t index);
bool good(void);
size_t size(void);
bool folder(size_t index);
bool good(void);
size_t size(void);
private:
std::vector
<FS_DirectoryEntry> mList;
Result mError;
bool mGood;
std::vector<FS_DirectoryEntry> mList;
Result mError;
bool mGood;
};
#endif

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef FSSTREAM_HPP
#define FSSTREAM_HPP
@ -30,29 +30,28 @@
#include <3ds.h>
#include <string>
class FSStream
{
class FSStream {
public:
FSStream(FS_Archive archive, const std::u16string& path, u32 flags);
FSStream(FS_Archive archive, const std::u16string& path, u32 flags, u32 size);
~FSStream(void) { };
~FSStream(void){};
Result close(void);
bool eof(void);
bool good(void);
void offset(u32 o);
u32 offset(void);
u32 read(void *buf, u32 size);
bool eof(void);
bool good(void);
void offset(u32 o);
u32 offset(void);
u32 read(void* buf, u32 size);
Result result(void);
u32 size(void);
u32 write(const void *buf, u32 size);
u32 size(void);
u32 write(const void* buf, u32 size);
private:
Handle mHandle;
u32 mSize;
u32 mOffset;
u32 mSize;
u32 mOffset;
Result mResult;
bool mGood;
bool mGood;
};
#endif

View file

@ -1,80 +1,78 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef GUI_HPP
#define GUI_HPP
#include <citro2d.h>
#include <algorithm>
#include <codecvt>
#include <locale>
#include <string>
#include <vector>
#include "archive.hpp"
#include "colors.hpp"
#include "clickable.hpp"
#include "colors.hpp"
#include "hid.hpp"
#include "multiselection.hpp"
#include "scrollable.hpp"
#include "sprites.h"
#include "title.hpp"
#include "util.hpp"
#include <algorithm>
#include <citro2d.h>
#include <codecvt>
#include <locale>
#include <string>
#include <vector>
namespace Gui
{
void init(void);
void exit(void);
namespace Gui {
void init(void);
void exit(void);
bool askForConfirmation(const std::string& text);
void showError(Result res, const std::string& message);
void showInfo(const std::string& message);
void draw(void);
void drawCopy(const std::u16string& src, u32 offset, u32 size);
void frameEnd(void);
size_t index(void);
bool isBackupReleased(void);
bool isRestoreReleased(void);
bool isCheatReleased(void);
bool isPlayCoinsReleased(void);
bool askForConfirmation(const std::string& text);
void showError(Result res, const std::string& message);
void showInfo(const std::string& message);
void draw(void);
void drawCopy(const std::u16string& src, u32 offset, u32 size);
void frameEnd(void);
size_t index(void);
bool isBackupReleased(void);
bool isRestoreReleased(void);
bool isCheatReleased(void);
bool isPlayCoinsReleased(void);
std::string nameFromCell(size_t index);
void resetIndex(void);
void resetScrollableIndex(void);
size_t scrollableIndex(void);
void scrollableIndex(size_t index);
void updateButtons(void);
void updateSelector(void);
std::vector
<size_t> selectedEntries(void);
bool multipleSelectionEnabled(void);
void clearSelectedEntries(void);
void addSelectedEntry(size_t index);
void resetIndex(void);
void resetScrollableIndex(void);
size_t scrollableIndex(void);
void scrollableIndex(size_t index);
void updateButtons(void);
void updateSelector(void);
C2D_Image TWLIcon(void);
C2D_Image noIcon(void);
std::vector<size_t> selectedEntries(void);
bool multipleSelectionEnabled(void);
void clearSelectedEntries(void);
void addSelectedEntry(size_t index);
C2D_Image TWLIcon(void);
C2D_Image noIcon(void);
}
#endif

View file

@ -1,57 +1,46 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef HID_HPP
#define HID_HPP
#include <3ds.h>
#include "ihid.hpp"
#include <3ds.h>
class HidHorizontal : public IHidHorizontal
{
class HidHorizontal : public IHidHorizontal {
public:
HidHorizontal(size_t entries, size_t columns)
: IHidHorizontal(entries, columns) { mDelayTicks = 35000000; }
HidHorizontal(size_t entries, size_t columns) : IHidHorizontal(entries, columns) { mDelayTicks = 35000000; }
virtual ~HidHorizontal(void) { }
virtual ~HidHorizontal(void) {}
u64 down(void) override
{
return (u64)hidKeysDown();
}
u64 down(void) override { return (u64)hidKeysDown(); }
u64 held(void) override
{
return (u64)hidKeysHeld();
}
u64 held(void) override { return (u64)hidKeysHeld(); }
u64 tick(void) override
{
return svcGetSystemTick();
}
u64 tick(void) override { return svcGetSystemTick(); }
u64 _KEY_ZL(void) override { return KEY_ZL; }
u64 _KEY_ZR(void) override { return KEY_ZR; }
@ -61,28 +50,17 @@ public:
u64 _KEY_DOWN(void) override { return KEY_DOWN; }
};
class HidVertical : public IHidVertical
{
class HidVertical : public IHidVertical {
public:
HidVertical(size_t entries, size_t columns)
: IHidVertical(entries, columns) { mDelayTicks = 50000000; }
HidVertical(size_t entries, size_t columns) : IHidVertical(entries, columns) { mDelayTicks = 50000000; }
virtual ~HidVertical(void) { }
virtual ~HidVertical(void) {}
u64 down(void) override
{
return (u64)hidKeysDown();
}
u64 down(void) override { return (u64)hidKeysDown(); }
u64 held(void) override
{
return (u64)hidKeysHeld();
}
u64 held(void) override { return (u64)hidKeysHeld(); }
u64 tick(void) override
{
return svcGetSystemTick();
}
u64 tick(void) override { return svcGetSystemTick(); }
u64 _KEY_ZL(void) override { return KEY_ZL; }
u64 _KEY_ZR(void) override { return KEY_ZR; }

View file

@ -1,54 +1,53 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef IO_HPP
#define IO_HPP
#include <3ds.h>
#include "KeyboardManager.hpp"
#include "directory.hpp"
#include "fsstream.hpp"
#include "KeyboardManager.hpp"
#include "gui.hpp"
#include "util.hpp"
#include <3ds.h>
#define BUFFER_SIZE 0x50000
namespace io
{
void backup(size_t index);
void restore(size_t index);
namespace io {
void backup(size_t index);
void restore(size_t index);
Result copyDirectory(FS_Archive srcArch, FS_Archive dstArch, const std::u16string& srcPath, const std::u16string& dstPath);
void copyFile(FS_Archive srcArch, FS_Archive dstArch, const std::u16string& srcPath, const std::u16string& dstPath);
void copyFile(FS_Archive srcArch, FS_Archive dstArch, const std::u16string& srcPath, const std::u16string& dstPath);
Result createDirectory(FS_Archive archive, const std::u16string& path);
void deleteBackupFolder(const std::u16string& path);
void deleteBackupFolder(const std::u16string& path);
Result deleteFolderRecursively(FS_Archive arch, const std::u16string& path);
bool directoryExists(FS_Archive archive, const std::u16string& path);
bool fileExists(FS_Archive archive, const std::u16string& path);
bool fileExists(const std::string& path);
bool directoryExists(FS_Archive archive, const std::u16string& path);
bool fileExists(FS_Archive archive, const std::u16string& path);
bool fileExists(const std::string& path);
}
#endif

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef MAIN_HPP
#define MAIN_HPP

View file

@ -1,53 +1,48 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef SCROLLABLE_HPP
#define SCROLLABLE_HPP
#include <citro2d.h>
#include <vector>
#include "iscrollable.hpp"
#include "clickable.hpp"
#include "colors.hpp"
#include "hid.hpp"
#include "iscrollable.hpp"
#include "main.hpp"
#include <citro2d.h>
#include <vector>
class Scrollable : public IScrollable<u32>
{
class Scrollable : public IScrollable<u32> {
public:
Scrollable(int x, int y, u32 w, u32 h, size_t visibleEntries)
: IScrollable(x, y, w, h, visibleEntries)
Scrollable(int x, int y, u32 w, u32 h, size_t visibleEntries) : IScrollable(x, y, w, h, visibleEntries)
{
mHid = new HidVertical(visibleEntries, 1);
}
virtual ~Scrollable(void)
{
delete mHid;
}
virtual ~Scrollable(void) { delete mHid; }
void c2dText(size_t i, const std::string& v);
void draw(bool condition = false) override;

View file

@ -1,35 +1,35 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef SMDH_HPP
#define SMDH_HPP
#include <3ds.h>
#include <string>
#include <stdio.h>
#include <string>
typedef struct {
u32 magic;

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
/*
* This file is part of TWLSaveTool.
@ -56,7 +56,7 @@ extern "C" {
#define SPI_512B_EEPROM_CMD_RDLO 3
#define SPI_512B_EEPROM_CMD_RDHI 11
#define SPI_EEPROM_CMD_WRITE 2
#define SPI_EEPROM_CMD_WRITE 2
#define SPI_CMD_PP 2
#define SPI_CMD_READ 3
@ -70,30 +70,30 @@ extern "C" {
#define SPI_FLG_WIP 1
#define SPI_FLG_WEL 2
extern u8* fill_buf;
extern u8* fill_buf;
typedef enum {
NO_CHIP = -1,
EEPROM_512B = 0,
EEPROM_8KB = 1,
EEPROM_64KB = 2,
EEPROM_128KB = 3,
EEPROM_8KB = 1,
EEPROM_64KB = 2,
EEPROM_128KB = 3,
EEPROM_STD_DUMMY = 1,
FLASH_256KB_1 = 4,
FLASH_256KB_2 = 5,
FLASH_512KB_1 = 6,
FLASH_512KB_2 = 7,
FLASH_1MB = 8,
FLASH_8MB = 9, // <- can't restore savegames, and maybe not read them atm
FLASH_256KB_1 = 4,
FLASH_256KB_2 = 5,
FLASH_512KB_1 = 6,
FLASH_512KB_2 = 7,
FLASH_1MB = 8,
FLASH_8MB = 9, // <- can't restore savegames, and maybe not read them atm
FLASH_STD_DUMMY = 4,
FLASH_512KB_INFRARED = 10,
FLASH_256KB_INFRARED = 11, // AFAIK, only "Active Health with Carol Vorderman" has such a flash save memory
FLASH_INFRARED_DUMMY = 9,
CHIP_LAST = 11,
} CardType;

View file

@ -1,38 +1,37 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef THREAD_HPP
#define THREAD_HPP
#include "title.hpp"
#include <3ds.h>
#include <vector>
#include "title.hpp"
namespace Threads
{
namespace Threads {
void create(ThreadFunc entrypoint);
void destroy(void);
void titles(void);

View file

@ -1,45 +1,45 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef TITLE_HPP
#define TITLE_HPP
#include <algorithm>
#include <citro2d.h>
#include <string>
#include <vector>
#include "archive.hpp"
#include "configuration.hpp"
#include "directory.hpp"
#include "fsstream.hpp"
#include "io.hpp"
#include "gui.hpp"
#include "io.hpp"
#include "smdh.hpp"
#include "spi.hpp"
#include "util.hpp"
#include <algorithm>
#include <citro2d.h>
#include <string>
#include <vector>
extern "C" {
#include "sha256.h"
@ -47,73 +47,67 @@ extern "C" {
#define TID_PKSM 0x000400000EC10000
class Title
{
class Title {
public:
bool accessibleSave(void);
bool accessibleExtdata(void);
FS_CardType cardType(void);
std::vector
<std::u16string> extdata(void);
u32 extdataId(void);
std::u16string extdataPath(void);
std::u16string fullExtdataPath(size_t index);
u32 highId(void);
C2D_Image icon(void);
u64 id(void);
bool isActivityLog(void);
void load(void);
bool load(u64 id, FS_MediaType mediaType, FS_CardType cardType);
void load(u64 id, u8* productCode, bool accessibleSave, bool accessibleExtdata, std::u16string shortDescription, std::u16string longDescription, std::u16string savePath, std::u16string extdataPath, FS_MediaType media, FS_CardType cardType, CardType card);
std::string longDescription(void);
std::u16string getLongDescription(void);
u32 lowId(void);
FS_MediaType mediaType(void);
std::string mediaTypeString(void);
void refreshDirectories(void);
std::u16string savePath(void);
std::u16string fullSavePath(size_t index);
std::vector
<std::u16string> saves(void);
void setIcon(C2D_Image icon);
std::string shortDescription(void);
std::u16string getShortDescription(void);
CardType SPICardType(void);
u32 uniqueId(void);
bool accessibleSave(void);
bool accessibleExtdata(void);
FS_CardType cardType(void);
std::vector<std::u16string> extdata(void);
u32 extdataId(void);
std::u16string extdataPath(void);
std::u16string fullExtdataPath(size_t index);
u32 highId(void);
C2D_Image icon(void);
u64 id(void);
bool isActivityLog(void);
void load(void);
bool load(u64 id, FS_MediaType mediaType, FS_CardType cardType);
void load(u64 id, u8* productCode, bool accessibleSave, bool accessibleExtdata, std::u16string shortDescription, std::u16string longDescription,
std::u16string savePath, std::u16string extdataPath, FS_MediaType media, FS_CardType cardType, CardType card);
std::string longDescription(void);
std::u16string getLongDescription(void);
u32 lowId(void);
FS_MediaType mediaType(void);
std::string mediaTypeString(void);
void refreshDirectories(void);
std::u16string savePath(void);
std::u16string fullSavePath(size_t index);
std::vector<std::u16string> saves(void);
void setIcon(C2D_Image icon);
std::string shortDescription(void);
std::u16string getShortDescription(void);
CardType SPICardType(void);
u32 uniqueId(void);
char productCode[16];
char productCode[16];
private:
bool mAccessibleSave;
bool mAccessibleExtdata;
std::u16string mShortDescription;
std::u16string mLongDescription;
std::u16string mSavePath;
std::u16string mExtdataPath;
std::vector
<std::u16string> mSaves;
std::vector
<std::u16string> mFullSavePaths;
std::vector
<std::u16string> mExtdata;
std::vector
<std::u16string> mFullExtdataPaths;
u64 mId;
FS_MediaType mMedia;
FS_CardType mCard;
CardType mCardType;
C2D_Image mIcon;
bool mAccessibleSave;
bool mAccessibleExtdata;
std::u16string mShortDescription;
std::u16string mLongDescription;
std::u16string mSavePath;
std::u16string mExtdataPath;
std::vector<std::u16string> mSaves;
std::vector<std::u16string> mFullSavePaths;
std::vector<std::u16string> mExtdata;
std::vector<std::u16string> mFullExtdataPaths;
u64 mId;
FS_MediaType mMedia;
FS_CardType mCard;
CardType mCardType;
C2D_Image mIcon;
};
void getTitle(Title &dst, int i);
int getTitleCount(void);
void getTitle(Title& dst, int i);
int getTitleCount(void);
C2D_Image icon(int i);
bool favorite(int i);
bool favorite(int i);
void loadFilter(void);
void loadTitles(bool forceRefresh);
void refreshDirectories(u64 id);
void updateCard(void);
void loadFilter(void);
void loadTitles(bool forceRefresh);
void refreshDirectories(u64 id);
void updateCard(void);
#endif

View file

@ -1,40 +1,40 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef UTIL_HPP
#define UTIL_HPP
#include "archive.hpp"
#include "cheatmanager.hpp"
#include "common.hpp"
#include <3ds.h>
#include <citro2d.h>
#include <map>
#include <queue>
#include <sys/stat.h>
#include "common.hpp"
#include "archive.hpp"
#include "cheatmanager.hpp"
#include "gui.hpp"
extern "C" {
#include "sha256.h"
@ -44,8 +44,7 @@ void calculateTitleDBHash(u8* hash);
void servicesExit(void);
Result servicesInit(void);
namespace StringUtils
{
namespace StringUtils {
std::u16string removeForbiddenCharacters(std::u16string src);
std::u16string UTF8toUTF16(const char* src);
std::string splitWord(const std::string& text, float scaleX, float maxWidth);

View file

@ -2,10 +2,10 @@
std::u16string KeyboardManager::keyboard(const std::string& suggestion)
{
swkbdSetInitialText(&mSwkbd, suggestion.c_str());
swkbdSetInitialText(&mSwkbd, suggestion.c_str());
char buf[CUSTOM_PATH_LEN] = {0};
SwkbdButton button = swkbdInputText(&mSwkbd, buf, CUSTOM_PATH_LEN);
buf[CUSTOM_PATH_LEN - 1] = '\0';
SwkbdButton button = swkbdInputText(&mSwkbd, buf, CUSTOM_PATH_LEN);
buf[CUSTOM_PATH_LEN - 1] = '\0';
return button == SWKBD_BUTTON_CONFIRM ? StringUtils::removeForbiddenCharacters(StringUtils::UTF8toUTF16(buf)) : StringUtils::UTF8toUTF16(" ");
}
@ -15,14 +15,14 @@ int KeyboardManager::numericPad(void)
swkbdInit(&swkbd, SWKBD_TYPE_NUMPAD, 2, 3);
swkbdSetFeatures(&swkbd, SWKBD_FIXED_WIDTH);
swkbdSetValidation(&swkbd, SWKBD_NOTBLANK_NOTEMPTY, 0, 0);
char buf[4] = {0};
char buf[4] = {0};
SwkbdButton button = swkbdInputText(&swkbd, buf, sizeof(buf));
buf[3] = '\0';
buf[3] = '\0';
return button == SWKBD_BUTTON_CONFIRM ? atoi(buf) : -1;
}
KeyboardManager::KeyboardManager(void)
{
swkbdInit(&mSwkbd, SWKBD_TYPE_NORMAL, 2, CUSTOM_PATH_LEN - 1);
swkbdSetHintText(&mSwkbd, "Choose a name for your backup.");
swkbdInit(&mSwkbd, SWKBD_TYPE_NORMAL, 2, CUSTOM_PATH_LEN - 1);
swkbdSetHintText(&mSwkbd, "Choose a name for your backup.");
}

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "archive.hpp"
@ -56,14 +56,12 @@ FS_Archive Archive::sdmc(void)
Result Archive::save(FS_Archive* archive, FS_MediaType mediatype, u32 lowid, u32 highid)
{
if (mediatype == MEDIATYPE_NAND)
{
const u32 path[2] = { mediatype, (0x00020000 | lowid >> 8) };
return FSUSER_OpenArchive(archive, ARCHIVE_SYSTEM_SAVEDATA, {PATH_BINARY, 8, path});
if (mediatype == MEDIATYPE_NAND) {
const u32 path[2] = {mediatype, (0x00020000 | lowid >> 8)};
return FSUSER_OpenArchive(archive, ARCHIVE_SYSTEM_SAVEDATA, {PATH_BINARY, 8, path});
}
else
{
const u32 path[3] = { mediatype, lowid, highid };
else {
const u32 path[3] = {mediatype, lowid, highid};
return FSUSER_OpenArchive(archive, ARCHIVE_USER_SAVEDATA, {PATH_BINARY, 12, path});
}
return 0;
@ -71,7 +69,7 @@ Result Archive::save(FS_Archive* archive, FS_MediaType mediatype, u32 lowid, u32
Result Archive::extdata(FS_Archive* archive, u32 ext)
{
const u32 path[3] = { MEDIATYPE_SD, ext, 0 };
const u32 path[3] = {MEDIATYPE_SD, ext, 0};
return FSUSER_OpenArchive(archive, ARCHIVE_EXTDATA, {PATH_BINARY, 12, path});
}
@ -79,8 +77,7 @@ bool Archive::accessible(FS_MediaType mediatype, u32 lowid, u32 highid)
{
FS_Archive archive;
Result res = save(&archive, mediatype, lowid, highid);
if (R_SUCCEEDED(res))
{
if (R_SUCCEEDED(res)) {
FSUSER_CloseArchive(archive);
return true;
}
@ -91,8 +88,7 @@ bool Archive::accessible(u32 ext)
{
FS_Archive archive;
Result res = extdata(&archive, ext);
if (R_SUCCEEDED(res))
{
if (R_SUCCEEDED(res)) {
FSUSER_CloseArchive(archive);
return true;
}
@ -102,17 +98,14 @@ bool Archive::accessible(u32 ext)
bool Archive::setPlayCoins(void)
{
FS_Archive archive;
const u32 path[3] = { MEDIATYPE_NAND, 0xF000000B, 0x00048000 };
Result res = FSUSER_OpenArchive(&archive, ARCHIVE_SHARED_EXTDATA, {PATH_BINARY, 0xC, path});
if (R_SUCCEEDED(res))
{
const u32 path[3] = {MEDIATYPE_NAND, 0xF000000B, 0x00048000};
Result res = FSUSER_OpenArchive(&archive, ARCHIVE_SHARED_EXTDATA, {PATH_BINARY, 0xC, path});
if (R_SUCCEEDED(res)) {
FSStream s(archive, StringUtils::UTF8toUTF16("/gamecoin.dat"), FS_OPEN_READ | FS_OPEN_WRITE);
if (s.good())
{
if (s.good()) {
u8 buf[2];
int coinAmount = KeyboardManager::get().numericPad();
if (coinAmount >= 0)
{
if (coinAmount >= 0) {
coinAmount = coinAmount > 300 ? 300 : coinAmount;
s.offset(4);
buf[0] = (u8)coinAmount;

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "cheatmanager.hpp"
@ -36,35 +36,30 @@ void CheatManager::init(void)
{
Gui::updateButtons();
if (io::fileExists("/3ds/Checkpoint/cheats.json"))
{
if (io::fileExists("/3ds/Checkpoint/cheats.json")) {
const std::string path = "/3ds/Checkpoint/cheats.json";
FILE* in = fopen(path.c_str(), "rt");
if (in != NULL)
{
FILE* in = fopen(path.c_str(), "rt");
if (in != NULL) {
mCheats = nlohmann::json::parse(in, nullptr, false);
fclose(in);
mLoaded = true;
}
}
else
{
else {
const std::string path = "romfs:/cheats/cheats.json.bz2";
// load compressed archive in memory
FILE* f = fopen(path.c_str(), "rb");
if (f != NULL)
{
if (f != NULL) {
fseek(f, 0, SEEK_END);
u32 size = ftell(f);
unsigned int destLen = 2*1024*1024;
char* s = new char[size];
char* d = new char[destLen]();
u32 size = ftell(f);
unsigned int destLen = 2 * 1024 * 1024;
char* s = new char[size];
char* d = new char[destLen]();
rewind(f);
fread(s, 1, size, f);
int r = BZ2_bzBuffToBuffDecompress(d, &destLen, s, size, 0, 0);
if (r == BZ_OK)
{
if (r == BZ_OK) {
mCheats = nlohmann::json::parse(d);
mLoaded = true;
}
@ -74,14 +69,11 @@ void CheatManager::init(void)
fclose(f);
}
}
Gui::updateButtons();
}
void CheatManager::exit(void)
{
}
void CheatManager::exit(void) {}
bool CheatManager::loaded(void)
{
@ -96,12 +88,11 @@ bool CheatManager::availableCodes(const std::string& key)
void CheatManager::manageCheats(const std::string& key)
{
std::string existingCheat = "";
FILE* f = fopen(("/cheats/" + key + ".txt").c_str(), "r");
if (f != NULL)
{
FILE* f = fopen(("/cheats/" + key + ".txt").c_str(), "r");
if (f != NULL) {
fseek(f, 0, SEEK_END);
u32 size = ftell(f);
char* s = new char[size];
char* s = new char[size];
rewind(f);
fread(s, 1, size, f);
existingCheat = std::string(s);
@ -109,14 +100,12 @@ void CheatManager::manageCheats(const std::string& key)
fclose(f);
}
size_t i = 0;
size_t i = 0;
size_t currentIndex = i;
Scrollable* s = new Scrollable(2, 2, 396, 220, 11);
for (auto it = mCheats[key].begin(); it != mCheats[key].end(); ++it)
{
Scrollable* s = new Scrollable(2, 2, 396, 220, 11);
for (auto it = mCheats[key].begin(); it != mCheats[key].end(); ++it) {
std::string value = it.key();
if (existingCheat.find(value) != std::string::npos)
{
if (existingCheat.find(value) != std::string::npos) {
value = SELECTED_MAGIC + value;
}
s->push_back(COLOR_GREY_DARKER, COLOR_WHITE, value, i == 0);
@ -130,58 +119,46 @@ void CheatManager::manageCheats(const std::string& key)
C2D_TextOptimize(&multiSelectText);
C2D_TextOptimize(&multiDeselectText);
while(aptMainLoop())
{
while (aptMainLoop()) {
hidScanInput();
if (hidKeysDown() & KEY_B)
{
if (hidKeysDown() & KEY_B) {
break;
}
if (hidKeysDown() & KEY_A)
{
if (hidKeysDown() & KEY_A) {
std::string cellName = s->cellName(s->index());
if (cellName.find(SELECTED_MAGIC, 0) == 0)
{
if (cellName.find(SELECTED_MAGIC, 0) == 0) {
// cheat was already selected
cellName = cellName.substr(strlen(SELECTED_MAGIC), cellName.length());
}
else
{
else {
cellName = SELECTED_MAGIC + cellName;
}
s->c2dText(s->index(), cellName);
}
if (hidKeysDown() & KEY_Y)
{
if (multiSelected)
{
for (size_t i = 0; i < s->size(); i++)
{
if (hidKeysDown() & KEY_Y) {
if (multiSelected) {
for (size_t i = 0; i < s->size(); i++) {
std::string cellName = s->cellName(i);
if (cellName.find(SELECTED_MAGIC, 0) == 0)
{
if (cellName.find(SELECTED_MAGIC, 0) == 0) {
cellName = cellName.substr(strlen(SELECTED_MAGIC), cellName.length());
s->c2dText(i, cellName);
}
}
}
multiSelected = false;
}
else
{
for (size_t i = 0; i < s->size(); i++)
{
else {
for (size_t i = 0; i < s->size(); i++) {
std::string cellName = s->cellName(i);
if (cellName.find(SELECTED_MAGIC, 0) != 0)
{
if (cellName.find(SELECTED_MAGIC, 0) != 0) {
cellName = SELECTED_MAGIC + cellName;
s->c2dText(i, cellName);
}
s->c2dText(i, cellName);
}
}
multiSelected = true;
}
}
}
s->updateSelection();
@ -203,8 +180,7 @@ void CheatManager::manageCheats(const std::string& key)
}
Gui::draw();
if (Gui::askForConfirmation("Do you want to store\nthe cheat file?"))
{
if (Gui::askForConfirmation("Do you want to store\nthe cheat file?")) {
save(key, s);
}
@ -214,15 +190,12 @@ void CheatManager::manageCheats(const std::string& key)
void CheatManager::save(const std::string& key, Scrollable* s)
{
std::string cheatFile = "";
for (size_t i = 0; i < s->size(); i++)
{
for (size_t i = 0; i < s->size(); i++) {
std::string cellName = s->cellName(i);
if (cellName.find(SELECTED_MAGIC, 0) == 0)
{
if (cellName.find(SELECTED_MAGIC, 0) == 0) {
cellName = cellName.substr(strlen(SELECTED_MAGIC), cellName.length());
cheatFile += cellName + "\n";
for (auto &it : mCheats[key][cellName])
{
for (auto& it : mCheats[key][cellName]) {
cheatFile += it.get<std::string>() + "\n";
}
cheatFile += "\n";
@ -230,13 +203,11 @@ void CheatManager::save(const std::string& key, Scrollable* s)
}
FILE* f = fopen(("/cheats/" + key + ".txt").c_str(), "w");
if (f != NULL)
{
if (f != NULL) {
fwrite(cheatFile.c_str(), 1, cheatFile.length(), f);
fclose(f);
}
else
{
else {
Gui::showError(errno, "Failed to write cheat file\nto the sd card");
}
}

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "clickable.hpp"
@ -38,51 +38,47 @@ bool Clickable::held()
{
touchPosition touch;
hidTouchRead(&touch);
return ((hidKeysHeld() & KEY_TOUCH) && touch.px > mx && touch.px < mx+mw && touch.py > my && touch.py < my+mh);
return ((hidKeysHeld() & KEY_TOUCH) && touch.px > mx && touch.px < mx + mw && touch.py > my && touch.py < my + mh);
}
bool Clickable::released(void)
{
touchPosition touch;
hidTouchRead(&touch);
const bool on = touch.px > mx && touch.px < mx+mw && touch.py > my && touch.py < my+mh;
if (on)
{
hidTouchRead(&touch);
const bool on = touch.px > mx && touch.px < mx + mw && touch.py > my && touch.py < my + mh;
if (on) {
mOldPressed = true;
}
else
{
if (mOldPressed && !(touch.px > 0 || touch.py > 0))
{
mOldPressed = false;
else {
if (mOldPressed && !(touch.px > 0 || touch.py > 0)) {
mOldPressed = false;
return true;
}
mOldPressed = false;
}
return false;
}
void Clickable::draw(float size, u32 overlay)
{
const u8 r = overlay & 0xFF;
const u8 g = (overlay >> 8) & 0xFF;
const u8 b = (overlay >> 16) & 0xFF;
const u8 r = overlay & 0xFF;
const u8 g = (overlay >> 8) & 0xFF;
const u8 b = (overlay >> 16) & 0xFF;
const float messageHeight = ceilf(size * fontGetInfo()->lineFeed);
const float messageWidth = mCentered ? mC2dText.width * size : mw - (mSelected ? 20 : 8);
const float messageWidth = mCentered ? mC2dText.width * size : mw - (mSelected ? 20 : 8);
C2D_DrawRectSolid(mx, my, 0.5f, mw, mh, mColorBg);
if (mCanChangeColorWhenSelected && held())
{
if (mCanChangeColorWhenSelected && held()) {
C2D_DrawRectSolid(mx, my, 0.5f, mw, mh, C2D_Color32(r, g, b, 100));
}
if (mSelected)
{
if (mSelected) {
C2D_DrawRectSolid(mx + 4, my + 6, 0.5f, 4, mh - 12, COLOR_WHITE);
C2D_DrawRectSolid(mx, my, 0.5f, mw, mh, C2D_Color32(r, g, b, 100));
}
C2D_DrawText(&mC2dText, C2D_WithColor, ceilf(mx + (mSelected ? 8 : 0) + (mw - messageWidth)/2), ceilf(my + (mh - messageHeight) / 2), 0.5f, size, size, mColorText);
C2D_DrawText(&mC2dText, C2D_WithColor, ceilf(mx + (mSelected ? 8 : 0) + (mw - messageWidth) / 2), ceilf(my + (mh - messageHeight) / 2), 0.5f,
size, size, mColorText);
}
void Clickable::drawOutline(u32 color)

View file

@ -1,74 +1,67 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "configuration.hpp"
Configuration::Configuration(void)
{
// check for existing config.json files on the sd card, BASEPATH
if (!io::fileExists(Archive::sdmc(), StringUtils::UTF8toUTF16(BASEPATH.c_str())))
{
if (!io::fileExists(Archive::sdmc(), StringUtils::UTF8toUTF16(BASEPATH.c_str()))) {
store();
}
mJson = loadJson(BASEPATH);
bool updateJson = false;
if (mJson.find("version") == mJson.end())
{
if (mJson.find("version") == mJson.end()) {
// if config is present but is < 3.4.2, override it
store();
}
else
{
else {
// 3.4.2 -> 3.5.0
if (mJson["version"] < 2)
{
if (mJson["version"] < 2) {
mJson["favorites"] = nlohmann::json::array();
updateJson = true;
updateJson = true;
}
}
if (updateJson)
{
if (updateJson) {
mJson["version"] = CONFIG_VERSION;
storeJson(mJson, BASEPATH);
}
// parse filters
std::vector<std::string> filter = mJson["filter"];
for (auto& id : filter)
{
for (auto& id : filter) {
mFilterIds.emplace(strtoull(id.c_str(), NULL, 16));
}
// parse favorites
std::vector<std::string> favorites = mJson["favorites"];
for (auto& id : favorites)
{
for (auto& id : favorites) {
mFavoriteIds.emplace(strtoull(id.c_str(), NULL, 16));
}
@ -77,12 +70,10 @@ Configuration::Configuration(void)
// parse additional save folders
auto js = mJson["additional_save_folders"];
for (auto it = js.begin(); it != js.end(); ++it)
{
for (auto it = js.begin(); it != js.end(); ++it) {
std::vector<std::string> folders = it.value()["folders"];
std::vector<std::u16string> u16folders;
for (auto& folder : folders)
{
for (auto& folder : folders) {
u16folders.push_back(StringUtils::UTF8toUTF16(folder.c_str()));
}
mAdditionalSaveFolders.emplace(strtoull(it.key().c_str(), NULL, 16), u16folders);
@ -90,12 +81,10 @@ Configuration::Configuration(void)
// parse additional extdata folders
auto je = mJson["additional_extdata_folders"];
for (auto it = je.begin(); it != je.end(); ++it)
{
for (auto it = je.begin(); it != je.end(); ++it) {
std::vector<std::string> folders = it.value()["folders"];
std::vector<std::u16string> u16folders;
for (auto& folder : folders)
{
for (auto& folder : folders) {
u16folders.push_back(StringUtils::UTF8toUTF16(folder.c_str()));
}
mAdditionalExtdataFolders.emplace(strtoull(it.key().c_str(), NULL, 16), u16folders);
@ -106,8 +95,7 @@ nlohmann::json Configuration::loadJson(const std::string& path)
{
nlohmann::json json;
FILE* in = fopen(path.c_str(), "rt");
if (in != NULL)
{
if (in != NULL) {
json = nlohmann::json::parse(in, nullptr, false);
fclose(in);
}
@ -121,8 +109,7 @@ void Configuration::storeJson(nlohmann::json& json, const std::string& path)
size_t size = writeData.size();
FILE* out = fopen(path.c_str(), "wt");
if (out != NULL)
{
if (out != NULL) {
fwrite(writeData.c_str(), 1, size, out);
fclose(out);
}

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "directory.hpp"
@ -31,30 +31,27 @@ Directory::Directory(FS_Archive archive, const std::u16string& root)
mGood = false;
mList.clear();
Handle handle;
mError = FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, root.data()));
if (R_FAILED(mError))
{
if (R_FAILED(mError)) {
return;
}
u32 result;
do {
FS_DirectoryEntry item;
mError = FSDIR_Read(handle, &result, 1, &item);
if (result == 1)
{
if (result == 1) {
mList.push_back(item);
}
} while(result);
} while (result);
mError = FSDIR_Close(handle);
if (R_FAILED(mError))
{
if (R_FAILED(mError)) {
mList.clear();
return;
}
mGood = true;
}
@ -75,7 +72,7 @@ std::u16string Directory::entry(size_t index)
bool Directory::folder(size_t index)
{
return index < mList.size() ? mList.at(index).attributes == FS_ATTRIBUTE_DIRECTORY : false;
return index < mList.size() ? mList.at(index).attributes == FS_ATTRIBUTE_DIRECTORY : false;
}
size_t Directory::size(void)

View file

@ -1,40 +1,39 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "fsstream.hpp"
FSStream::FSStream(FS_Archive archive, const std::u16string& path, u32 flags)
{
mGood = false;
mSize = 0;
mGood = false;
mSize = 0;
mOffset = 0;
mResult = FSUSER_OpenFile(&mHandle, archive, fsMakePath(PATH_UTF16, path.data()), flags, 0);
if (R_SUCCEEDED(mResult))
{
if (R_SUCCEEDED(mResult)) {
FSFILE_GetSize(mHandle, (u64*)&mSize);
mGood = true;
}
@ -42,25 +41,21 @@ FSStream::FSStream(FS_Archive archive, const std::u16string& path, u32 flags)
FSStream::FSStream(FS_Archive archive, const std::u16string& path, u32 flags, u32 size)
{
mGood = false;
mSize = size;
mGood = false;
mSize = size;
mOffset = 0;
mResult = FSUSER_OpenFile(&mHandle, archive, fsMakePath(PATH_UTF16, path.data()), flags, 0);
if (R_FAILED(mResult))
{
if (R_FAILED(mResult)) {
mResult = FSUSER_CreateFile(archive, fsMakePath(PATH_UTF16, path.data()), 0, mSize);
if (R_SUCCEEDED(mResult))
{
if (R_SUCCEEDED(mResult)) {
mResult = FSUSER_OpenFile(&mHandle, archive, fsMakePath(PATH_UTF16, path.data()), flags, 0);
if (R_SUCCEEDED(mResult))
{
if (R_SUCCEEDED(mResult)) {
mGood = true;
}
}
}
else
{
else {
mGood = true;
}
}
@ -86,14 +81,12 @@ u32 FSStream::size(void)
return mSize;
}
u32 FSStream::read(void *buf, u32 sz)
u32 FSStream::read(void* buf, u32 sz)
{
u32 rd = 0;
u32 rd = 0;
mResult = FSFILE_Read(mHandle, &rd, mOffset, buf, sz);
if (R_FAILED(mResult))
{
if (rd > sz)
{
if (R_FAILED(mResult)) {
if (rd > sz) {
rd = sz;
}
}
@ -101,9 +94,9 @@ u32 FSStream::read(void *buf, u32 sz)
return rd;
}
u32 FSStream::write(const void *buf, u32 sz)
u32 FSStream::write(const void* buf, u32 sz)
{
u32 wt = 0;
u32 wt = 0;
mResult = FSFILE_Write(mHandle, &wt, mOffset, buf, sz, FS_WRITE_FLUSH);
mOffset += wt;
return wt;

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "gui.hpp"
@ -82,9 +82,9 @@ void Gui::drawCopy(const std::u16string& src, u32 offset, u32 size)
C2D_TextOptimize(&srcText);
C2D_TextOptimize(&copyText);
const float scale = 0.6f;
const u32 size_h = scale * fontGetInfo()->lineFeed;
const u32 src_w = StringUtils::textWidth(srcText, scale);
const u32 size_w = StringUtils::textWidth(copyText, scale);
const u32 size_h = scale * fontGetInfo()->lineFeed;
const u32 src_w = StringUtils::textWidth(srcText, scale);
const u32 size_w = StringUtils::textWidth(copyText, scale);
C2D_TextBufClear(g_dynamicBuf);
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
@ -98,29 +98,23 @@ void Gui::drawCopy(const std::u16string& src, u32 offset, u32 size)
bool Gui::askForConfirmation(const std::string& message)
{
bool ret = false;
bool ret = false;
Clickable* buttonYes = new Clickable(42, 162, 116, 36, COLOR_GREY_DARK, COLOR_WHITE, "\uE000 Yes", true);
Clickable* buttonNo = new Clickable(162, 162, 116, 36, COLOR_GREY_DARK, COLOR_WHITE, "\uE001 No", true);
HidHorizontal* hid = new HidHorizontal(2, 2);
Clickable* buttonNo = new Clickable(162, 162, 116, 36, COLOR_GREY_DARK, COLOR_WHITE, "\uE001 No", true);
HidHorizontal* hid = new HidHorizontal(2, 2);
C2D_Text text;
C2D_TextParse(&text, g_dynamicBuf, message.c_str());
C2D_TextOptimize(&text);
while(aptMainLoop())
{
while (aptMainLoop()) {
hidScanInput();
hid->update(2);
if (buttonYes->released() ||
((hidKeysDown() & KEY_A) && hid->index() == 0))
{
if (buttonYes->released() || ((hidKeysDown() & KEY_A) && hid->index() == 0)) {
ret = true;
break;
}
else if (buttonNo->released() ||
(hidKeysDown() & KEY_B) ||
((hidKeysDown() & KEY_A) && hid->index() == 1))
{
else if (buttonNo->released() || (hidKeysDown() & KEY_B) || ((hidKeysDown() & KEY_A) && hid->index() == 1)) {
break;
}
@ -132,18 +126,17 @@ bool Gui::askForConfirmation(const std::string& message)
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_SceneBegin(g_bottom);
C2D_DrawRectSolid(40, 40, 0.5f, 240, 160, COLOR_GREY_DARK);
C2D_DrawText(&text, C2D_WithColor, ceilf(320 - text.width * 0.6) / 2, 40 + ceilf(120 - 0.6f * fontGetInfo()->lineFeed) / 2, 0.5f, 0.6f, 0.6f, COLOR_WHITE);
C2D_DrawText(&text, C2D_WithColor, ceilf(320 - text.width * 0.6) / 2, 40 + ceilf(120 - 0.6f * fontGetInfo()->lineFeed) / 2, 0.5f, 0.6f, 0.6f,
COLOR_WHITE);
C2D_DrawRectSolid(40, 160, 0.5f, 240, 40, COLOR_GREY_LIGHT);
buttonYes->draw(0.7, 0);
buttonNo->draw(0.7, 0);
if (hid->index() == 0)
{
if (hid->index() == 0) {
drawPulsingOutline(42, 162, 116, 36, 2, COLOR_BLUE);
}
else
{
else {
drawPulsingOutline(162, 162, 116, 36, 2, COLOR_BLUE);
}
@ -158,7 +151,7 @@ bool Gui::askForConfirmation(const std::string& message)
void Gui::showInfo(const std::string& message)
{
const float size = 0.6f;
const float size = 0.6f;
Clickable* button = new Clickable(42, 162, 236, 36, COLOR_GREY_DARK, COLOR_WHITE, "OK", true);
button->selected(true);
std::string t = StringUtils::wrap(message, size, 220);
@ -168,14 +161,10 @@ void Gui::showInfo(const std::string& message)
u32 w = StringUtils::textWidth(text, size);
u32 h = StringUtils::textHeight(t, size);
while(aptMainLoop())
{
while (aptMainLoop()) {
hidScanInput();
if (button->released() ||
(hidKeysDown() & KEY_A) ||
(hidKeysDown() & KEY_B))
{
if (button->released() || (hidKeysDown() & KEY_A) || (hidKeysDown() & KEY_B)) {
break;
}
@ -194,7 +183,7 @@ void Gui::showInfo(const std::string& message)
void Gui::showError(Result res, const std::string& message)
{
const float size = 0.6f;
const float size = 0.6f;
Clickable* button = new Clickable(42, 162, 236, 36, COLOR_GREY_DARKER, COLOR_WHITE, "OK", true);
button->selected(true);
std::string t = StringUtils::wrap(message, size, 220);
@ -207,14 +196,10 @@ void Gui::showError(Result res, const std::string& message)
u32 w = StringUtils::textWidth(text, size);
u32 h = StringUtils::textHeight(t, size);
while(aptMainLoop())
{
while (aptMainLoop()) {
hidScanInput();
if (button->released() ||
(hidKeysDown() & KEY_A) ||
(hidKeysDown() & KEY_B))
{
if (button->released() || (hidKeysDown() & KEY_A) || (hidKeysDown() & KEY_B)) {
break;
}
@ -254,24 +239,24 @@ void Gui::init(void)
C2D_Init(C2D_DEFAULT_MAX_OBJECTS);
C2D_Prepare();
g_top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
g_top = C2D_CreateScreenTarget(GFX_TOP, GFX_LEFT);
g_bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
g_bottomScrollEnabled = false;
hid = new HidHorizontal(rowlen * collen, collen);
hid = new HidHorizontal(rowlen * collen, collen);
buttonBackup = new Clickable(204, 102, 110, 35, COLOR_GREY_DARKER, COLOR_WHITE, "Backup \uE004", true);
buttonRestore = new Clickable(204, 139, 110, 35, COLOR_GREY_DARKER, COLOR_WHITE, "Restore \uE005", true);
buttonCheats = new Clickable(204, 176, 110, 36, COLOR_GREY_DARKER, COLOR_WHITE, "Cheats", true);
buttonBackup = new Clickable(204, 102, 110, 35, COLOR_GREY_DARKER, COLOR_WHITE, "Backup \uE004", true);
buttonRestore = new Clickable(204, 139, 110, 35, COLOR_GREY_DARKER, COLOR_WHITE, "Restore \uE005", true);
buttonCheats = new Clickable(204, 176, 110, 36, COLOR_GREY_DARKER, COLOR_WHITE, "Cheats", true);
buttonPlayCoins = new Clickable(204, 176, 110, 36, COLOR_GREY_DARKER, COLOR_WHITE, "\uE075 Coins", true);
directoryList = new Scrollable(6, 102, 196, 110, 5);
directoryList = new Scrollable(6, 102, 196, 110, 5);
buttonBackup->canChangeColorWhenSelected(true);
buttonRestore->canChangeColorWhenSelected(true);
buttonCheats->canChangeColorWhenSelected(true);
buttonPlayCoins->canChangeColorWhenSelected(true);
spritesheet = C2D_SpriteSheetLoad("romfs:/gfx/sprites.t3x");
flag = C2D_SpriteSheetGetImage(spritesheet, sprites_checkpoint_idx);
flag = C2D_SpriteSheetGetImage(spritesheet, sprites_checkpoint_idx);
C2D_SpriteFromSheet(&checkbox, spritesheet, sprites_checkbox_idx);
C2D_SpriteSetDepth(&checkbox, 0.5f);
C2D_PlainImageTint(&checkboxTint, C2D_Color32(88, 88, 88, 255), 1.0f);
@ -281,7 +266,7 @@ void Gui::init(void)
char ver[10];
sprintf(ver, "v%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO);
g_staticBuf = C2D_TextBufNew(256);
g_staticBuf = C2D_TextBufNew(256);
g_dynamicBuf = C2D_TextBufNew(256);
C2D_TextParse(&ins1, g_staticBuf, "Hold SELECT to see commands. Press \uE002 for ");
C2D_TextParse(&ins2, g_staticBuf, "extdata");
@ -341,8 +326,7 @@ size_t Gui::index(void)
void Gui::updateButtons(void)
{
if (MS::multipleSelectionEnabled())
{
if (MS::multipleSelectionEnabled()) {
buttonRestore->canChangeColorWhenSelected(true);
buttonRestore->canChangeColorWhenSelected(false);
buttonCheats->canChangeColorWhenSelected(false);
@ -352,8 +336,7 @@ void Gui::updateButtons(void)
buttonCheats->setColors(COLOR_GREY_DARKER, COLOR_GREY_LIGHT);
buttonPlayCoins->setColors(COLOR_GREY_DARKER, COLOR_GREY_LIGHT);
}
else if (g_bottomScrollEnabled)
{
else if (g_bottomScrollEnabled) {
buttonBackup->canChangeColorWhenSelected(true);
buttonRestore->canChangeColorWhenSelected(true);
buttonCheats->canChangeColorWhenSelected(true);
@ -363,8 +346,7 @@ void Gui::updateButtons(void)
buttonCheats->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
buttonPlayCoins->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
}
else
{
else {
buttonBackup->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
buttonRestore->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
buttonCheats->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
@ -372,15 +354,13 @@ void Gui::updateButtons(void)
}
static bool shouldCheckCheatManager = true;
if (CheatManager::loaded() && shouldCheckCheatManager)
{
if (CheatManager::loaded() && shouldCheckCheatManager) {
buttonCheats->c2dText("Cheats");
buttonCheats->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
buttonPlayCoins->setColors(COLOR_GREY_DARKER, COLOR_WHITE);
shouldCheckCheatManager = false;
}
else if (!CheatManager::loaded())
{
else if (!CheatManager::loaded()) {
buttonCheats->c2dText("Loading...");
buttonCheats->setColors(COLOR_GREY_DARKER, COLOR_GREY_LIGHT);
buttonPlayCoins->setColors(COLOR_GREY_DARKER, COLOR_GREY_LIGHT);
@ -389,55 +369,52 @@ void Gui::updateButtons(void)
void Gui::updateSelector(void)
{
if (!g_bottomScrollEnabled)
{
if (getTitleCount() > 0)
{
if (!g_bottomScrollEnabled) {
if (getTitleCount() > 0) {
hid->update(getTitleCount());
directoryList->resetIndex();
}
}
else
{
else {
directoryList->updateSelection();
}
}
static void drawSelector(void)
{
static const int w = 2;
const int x = selectorX(hid->index());
const int y = selectorY(hid->index());
static const int w = 2;
const int x = selectorX(hid->index());
const int y = selectorY(hid->index());
float highlight_multiplier = fmax(0.0, fabs(fmod(g_timer, 1.0) - 0.5) / 0.5);
u8 r = COLOR_SELECTOR & 0xFF;
u8 g = (COLOR_SELECTOR >> 8) & 0xFF;
u8 b = (COLOR_SELECTOR >> 16) & 0xFF;
u8 r = COLOR_SELECTOR & 0xFF;
u8 g = (COLOR_SELECTOR >> 8) & 0xFF;
u8 b = (COLOR_SELECTOR >> 16) & 0xFF;
u32 color = C2D_Color32(r + (255 - r) * highlight_multiplier, g + (255 - g) * highlight_multiplier, b + (255 - b) * highlight_multiplier, 255);
C2D_DrawRectSolid( x, y, 0.5f, 50, 50, C2D_Color32(255, 255, 255, 100));
C2D_DrawRectSolid( x, y, 0.5f, 50, w, color); // g_top
C2D_DrawRectSolid( x, y + w, 0.5f, w, 50 - 2*w, color); // left
C2D_DrawRectSolid(x + 50 - w, y + w, 0.5f, w, 50 - 2*w, color); // right
C2D_DrawRectSolid( x, y + 50 - w, 0.5f, 50, w, color); // g_bottom
C2D_DrawRectSolid(x, y, 0.5f, 50, 50, C2D_Color32(255, 255, 255, 100));
C2D_DrawRectSolid(x, y, 0.5f, 50, w, color); // g_top
C2D_DrawRectSolid(x, y + w, 0.5f, w, 50 - 2 * w, color); // left
C2D_DrawRectSolid(x + 50 - w, y + w, 0.5f, w, 50 - 2 * w, color); // right
C2D_DrawRectSolid(x, y + 50 - w, 0.5f, 50, w, color); // g_bottom
}
static int selectorX(size_t i)
{
return 50*((i % (rowlen*collen)) % collen);
return 50 * ((i % (rowlen * collen)) % collen);
}
static int selectorY(size_t i)
{
return 20 + 50*((i % (rowlen*collen)) / collen);
return 20 + 50 * ((i % (rowlen * collen)) / collen);
}
void Gui::draw(void)
{
const float scaleInst = 0.7f;
auto selEnt = MS::selectedEntries();
const size_t entries = hid->maxVisibleEntries();
const size_t max = hid->maxEntries(getTitleCount()) + 1;
const Mode_t mode = Archive::mode();
auto selEnt = MS::selectedEntries();
const size_t entries = hid->maxVisibleEntries();
const size_t max = hid->maxEntries(getTitleCount()) + 1;
const Mode_t mode = Archive::mode();
C2D_TextBufClear(g_dynamicBuf);
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
@ -452,28 +429,23 @@ void Gui::draw(void)
C2D_TextParse(&timeText, g_dynamicBuf, DateTime::timeStr().c_str());
C2D_TextOptimize(&timeText);
C2D_DrawText(&timeText, C2D_WithColor, 4.0f, 3.0f, 0.5f, 0.45f, 0.45f, COLOR_GREY_LIGHT);
for (size_t k = hid->page()*entries; k < hid->page()*entries + max; k++)
{
for (size_t k = hid->page() * entries; k < hid->page() * entries + max; k++) {
C2D_DrawImageAt(icon(k), selectorX(k) + 1, selectorY(k) + 1, 0.5f, NULL, 1.0f, 1.0f);
}
if (getTitleCount() > 0)
{
if (getTitleCount() > 0) {
drawSelector();
}
for (size_t k = hid->page()*entries; k < hid->page()*entries + max; k++)
{
if (!selEnt.empty() && std::find(selEnt.begin(), selEnt.end(), k) != selEnt.end())
{
for (size_t k = hid->page() * entries; k < hid->page() * entries + max; k++) {
if (!selEnt.empty() && std::find(selEnt.begin(), selEnt.end(), k) != selEnt.end()) {
C2D_DrawRectSolid(selectorX(k) + 31, selectorY(k) + 31, 0.5f, 16, 16, COLOR_WHITE);
C2D_SpriteSetPos(&checkbox, selectorX(k) + 27, selectorY(k) + 27);
C2D_DrawSpriteTinted(&checkbox, &checkboxTint);
}
if (favorite(k))
{
if (favorite(k)) {
C2D_DrawRectSolid(selectorX(k) + 31, selectorY(k) + 3, 0.5f, 16, 16, COLOR_GOLD);
C2D_SpriteSetPos(&star, selectorX(k) + 27, selectorY(k) - 1);
C2D_DrawSpriteTinted(&star, &checkboxTint);
@ -482,39 +454,42 @@ void Gui::draw(void)
static const float border = ceilf((400 - (ins1.width + ins2.width + ins3.width) * 0.47f) / 2);
C2D_DrawText(&ins1, C2D_WithColor, border, 223, 0.5f, 0.47f, 0.47f, COLOR_WHITE);
C2D_DrawText(&ins2, C2D_WithColor, border + ceilf(ins1.width*0.47f), 223, 0.5f, 0.47f, 0.47f, Archive::mode() == MODE_SAVE ? COLOR_WHITE : COLOR_RED);
C2D_DrawText(&ins3, C2D_WithColor, border + ceilf((ins1.width + ins2.width)*0.47f), 223, 0.5f, 0.47f, 0.47f, COLOR_WHITE);
C2D_DrawText(
&ins2, C2D_WithColor, border + ceilf(ins1.width * 0.47f), 223, 0.5f, 0.47f, 0.47f, Archive::mode() == MODE_SAVE ? COLOR_WHITE : COLOR_RED);
C2D_DrawText(&ins3, C2D_WithColor, border + ceilf((ins1.width + ins2.width) * 0.47f), 223, 0.5f, 0.47f, 0.47f, COLOR_WHITE);
if (hidKeysHeld() & KEY_SELECT)
{
if (hidKeysHeld() & KEY_SELECT) {
const u32 inst_lh = scaleInst * fontGetInfo()->lineFeed;
const u32 inst_h = ceilf((240 - scaleInst * inst_lh * 6) / 2);
const u32 inst_h = ceilf((240 - scaleInst * inst_lh * 6) / 2);
C2D_DrawRectSolid(0, 0, 0.5f, 400, 240, C2D_Color32(0, 0, 0, 190));
C2D_DrawText(&top_move, C2D_WithColor, ceilf((400 - StringUtils::textWidth(top_move, scaleInst)) / 2), inst_h, 0.9f, scaleInst, scaleInst, COLOR_WHITE);
C2D_DrawText(&top_a, C2D_WithColor, ceilf((400 - StringUtils::textWidth(top_a, scaleInst)) / 2), inst_h + inst_lh * 1, 0.9f, scaleInst, scaleInst, COLOR_WHITE);
C2D_DrawText(&top_b, C2D_WithColor, ceilf((400 - StringUtils::textWidth(top_b, scaleInst)) / 2), inst_h + inst_lh * 2, 0.9f, scaleInst, scaleInst, COLOR_WHITE);
C2D_DrawText(&top_y, C2D_WithColor, ceilf((400 - StringUtils::textWidth(top_y, scaleInst)) / 2), inst_h + inst_lh * 3, 0.9f, scaleInst, scaleInst, COLOR_WHITE);
C2D_DrawText(&top_my, C2D_WithColor, ceilf((400 - StringUtils::textWidth(top_my, scaleInst)) / 2), inst_h + inst_lh * 4, 0.9f, scaleInst, scaleInst, COLOR_WHITE);
C2D_DrawText(&top_move, C2D_WithColor, ceilf((400 - StringUtils::textWidth(top_move, scaleInst)) / 2), inst_h, 0.9f, scaleInst, scaleInst,
COLOR_WHITE);
C2D_DrawText(&top_a, C2D_WithColor, ceilf((400 - StringUtils::textWidth(top_a, scaleInst)) / 2), inst_h + inst_lh * 1, 0.9f, scaleInst,
scaleInst, COLOR_WHITE);
C2D_DrawText(&top_b, C2D_WithColor, ceilf((400 - StringUtils::textWidth(top_b, scaleInst)) / 2), inst_h + inst_lh * 2, 0.9f, scaleInst,
scaleInst, COLOR_WHITE);
C2D_DrawText(&top_y, C2D_WithColor, ceilf((400 - StringUtils::textWidth(top_y, scaleInst)) / 2), inst_h + inst_lh * 3, 0.9f, scaleInst,
scaleInst, COLOR_WHITE);
C2D_DrawText(&top_my, C2D_WithColor, ceilf((400 - StringUtils::textWidth(top_my, scaleInst)) / 2), inst_h + inst_lh * 4, 0.9f, scaleInst,
scaleInst, COLOR_WHITE);
}
C2D_DrawText(&version, C2D_WithColor, 400 - 4 - ceilf(0.45f*version.width), 3.0f, 0.5f, 0.45f, 0.45f, COLOR_GREY_LIGHT);
C2D_DrawImageAt(flag, 400 - 24 - ceilf(version.width*0.45f), 0.0f, 0.5f, NULL, 1.0f, 1.0f);
C2D_DrawText(&checkpoint, C2D_WithColor, 400 - 6 - 0.45f*version.width - 0.5f*checkpoint.width - 19, 2.0f, 0.5f, 0.5f, 0.5f, COLOR_WHITE);
C2D_DrawText(&version, C2D_WithColor, 400 - 4 - ceilf(0.45f * version.width), 3.0f, 0.5f, 0.45f, 0.45f, COLOR_GREY_LIGHT);
C2D_DrawImageAt(flag, 400 - 24 - ceilf(version.width * 0.45f), 0.0f, 0.5f, NULL, 1.0f, 1.0f);
C2D_DrawText(&checkpoint, C2D_WithColor, 400 - 6 - 0.45f * version.width - 0.5f * checkpoint.width - 19, 2.0f, 0.5f, 0.5f, 0.5f, COLOR_WHITE);
C2D_SceneBegin(g_bottom);
C2D_DrawRectSolid(0, 0, 0.5f, 320, 19, COLOR_GREY_DARK);
C2D_DrawRectSolid(0, 221, 0.5f, 320, 19, COLOR_GREY_DARK);
if (getTitleCount() > 0)
{
if (getTitleCount() > 0) {
Title title;
getTitle(title, hid->fullIndex());
directoryList->flush();
std::vector<std::u16string> dirs = mode == MODE_SAVE ? title.saves() : title.extdata();
static std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
static std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
for (size_t i = 0; i < dirs.size(); i++)
{
for (size_t i = 0; i < dirs.size(); i++) {
directoryList->push_back(COLOR_GREY_DARKER, COLOR_WHITE, convert.to_bytes(dirs.at(i)), i == directoryList->index());
}
@ -557,20 +532,17 @@ void Gui::draw(void)
directoryList->draw(g_bottomScrollEnabled);
buttonBackup->draw(0.7, 0);
buttonRestore->draw(0.7, 0);
if (title.isActivityLog())
{
if (title.isActivityLog()) {
buttonPlayCoins->draw(0.7, 0);
}
else
{
else {
buttonCheats->draw(0.7, 0);
}
}
C2D_DrawText(&ins4, C2D_WithColor, ceilf((320 - ins4.width*0.47f) / 2), 223, 0.5f, 0.47f, 0.47f, COLOR_WHITE);
if (hidKeysHeld() & KEY_SELECT)
{
C2D_DrawText(&ins4, C2D_WithColor, ceilf((320 - ins4.width * 0.47f) / 2), 223, 0.5f, 0.47f, 0.47f, COLOR_WHITE);
if (hidKeysHeld() & KEY_SELECT) {
C2D_DrawRectSolid(0, 0, 0.5f, 320, 240, C2D_Color32(0, 0, 0, 190));
C2D_DrawText(&bot_ts, C2D_WithColor, 16, 124, 0.5f, scaleInst, scaleInst, COLOR_WHITE);
C2D_DrawText(&bot_x, C2D_WithColor, 16, 168, 0.5f, scaleInst, scaleInst, COLOR_WHITE);

View file

@ -2,21 +2,21 @@
void drawPulsingOutline(u32 x, u32 y, u16 w, u16 h, u8 size, u32 color)
{
u8 r = color & 0xFF;
u8 g = (color >> 8) & 0xFF;
u8 b = (color >> 16) & 0xFF;
u8 r = color & 0xFF;
u8 g = (color >> 8) & 0xFF;
u8 b = (color >> 16) & 0xFF;
float highlight_multiplier = fmax(0.0, fabs(fmod(g_timer, 1.0) - 0.5) / 0.5);
color = C2D_Color32(r + (255 - r) * highlight_multiplier, g + (255 - g) * highlight_multiplier, b + (255 - b) * highlight_multiplier, 255);
C2D_DrawRectSolid(x - size, y - size, 0.5f, w + 2*size, size, color); // g_top
C2D_DrawRectSolid(x - size, y, 0.5f, size, h, color); // left
C2D_DrawRectSolid(x + w, y, 0.5f, size, h, color); // right
C2D_DrawRectSolid(x - size, y + h, 0.5f, w + 2*size, size, color); // g_bottom
C2D_DrawRectSolid(x - size, y - size, 0.5f, w + 2 * size, size, color); // g_top
C2D_DrawRectSolid(x - size, y, 0.5f, size, h, color); // left
C2D_DrawRectSolid(x + w, y, 0.5f, size, h, color); // right
C2D_DrawRectSolid(x - size, y + h, 0.5f, w + 2 * size, size, color); // g_bottom
}
void drawOutline(u32 x, u32 y, u16 w, u16 h, u8 size, u32 color)
{
C2D_DrawRectSolid(x - size, y - size, 0.5f, w + 2*size, size, color); // g_top
C2D_DrawRectSolid(x - size, y, 0.5f, size, h, color); // left
C2D_DrawRectSolid(x + w, y, 0.5f, size, h, color); // right
C2D_DrawRectSolid(x - size, y + h, 0.5f, w + 2*size, size, color); // g_bottom
C2D_DrawRectSolid(x - size, y - size, 0.5f, w + 2 * size, size, color); // g_top
C2D_DrawRectSolid(x - size, y, 0.5f, size, h, color); // left
C2D_DrawRectSolid(x + w, y, 0.5f, size, h, color); // right
C2D_DrawRectSolid(x - size, y + h, 0.5f, w + 2 * size, size, color); // g_bottom
}

View file

@ -1,35 +1,35 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "io.hpp"
bool io::fileExists(const std::string& path)
{
struct stat buffer;
return (stat (path.c_str(), &buffer) == 0);
struct stat buffer;
return (stat(path.c_str(), &buffer) == 0);
}
bool io::fileExists(FS_Archive archive, const std::u16string& path)
@ -44,29 +44,26 @@ void io::copyFile(FS_Archive srcArch, FS_Archive dstArch, const std::u16string&
{
u32 size = 0;
FSStream input(srcArch, srcPath, FS_OPEN_READ);
if (input.good())
{
if (input.good()) {
size = input.size() > BUFFER_SIZE ? BUFFER_SIZE : input.size();
}
else
{
else {
return;
}
FSStream output(dstArch, dstPath, FS_OPEN_WRITE, input.size());
if (output.good())
{
size_t slashpos = srcPath.rfind(StringUtils::UTF8toUTF16("/"));
if (output.good()) {
size_t slashpos = srcPath.rfind(StringUtils::UTF8toUTF16("/"));
std::u16string name = srcPath.substr(slashpos + 1, srcPath.length() - slashpos - 1);
u32 rd;
u8* buf = new u8[size];
do {
rd = input.read(buf, size);
output.write(buf, rd);
Gui::drawCopy(name, input.offset(), input.size());
} while(!input.eof());
delete[] buf;
} while (!input.eof());
delete[] buf;
}
input.close();
@ -76,39 +73,33 @@ void io::copyFile(FS_Archive srcArch, FS_Archive dstArch, const std::u16string&
Result io::copyDirectory(FS_Archive srcArch, FS_Archive dstArch, const std::u16string& srcPath, const std::u16string& dstPath)
{
Result res = 0;
bool quit = false;
bool quit = false;
Directory items(srcArch, srcPath);
if (!items.good())
{
if (!items.good()) {
return items.error();
}
for (size_t i = 0, sz = items.size(); i < sz && !quit; i++)
{
for (size_t i = 0, sz = items.size(); i < sz && !quit; i++) {
std::u16string newsrc = srcPath + items.entry(i);
std::u16string newdst = dstPath + items.entry(i);
if (items.folder(i))
{
if (items.folder(i)) {
res = io::createDirectory(dstArch, newdst);
if (R_SUCCEEDED(res) || (u32)res == 0xC82044B9)
{
if (R_SUCCEEDED(res) || (u32)res == 0xC82044B9) {
newsrc += StringUtils::UTF8toUTF16("/");
newdst += StringUtils::UTF8toUTF16("/");
res = io::copyDirectory(srcArch, dstArch, newsrc, newdst);
}
else
{
else {
quit = true;
}
}
else
{
else {
io::copyFile(srcArch, dstArch, newsrc, newdst);
}
}
return res;
}
@ -121,13 +112,11 @@ bool io::directoryExists(FS_Archive archive, const std::u16string& path)
{
Handle handle;
if (R_FAILED(FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, path.data()))))
{
if (R_FAILED(FSUSER_OpenDirectory(&handle, archive, fsMakePath(PATH_UTF16, path.data())))) {
return false;
}
if (R_FAILED(FSDIR_Close(handle)))
{
if (R_FAILED(FSDIR_Close(handle))) {
return false;
}
@ -137,22 +126,18 @@ bool io::directoryExists(FS_Archive archive, const std::u16string& path)
Result io::deleteFolderRecursively(FS_Archive arch, const std::u16string& path)
{
Directory dir(arch, path);
if (!dir.good())
{
if (!dir.good()) {
return dir.error();
}
for (size_t i = 0, sz = dir.size(); i < sz; i++)
{
if (dir.folder(i))
{
for (size_t i = 0, sz = dir.size(); i < sz; i++) {
if (dir.folder(i)) {
std::u16string newpath = path + StringUtils::UTF8toUTF16("/") + dir.entry(i) + StringUtils::UTF8toUTF16("/");
deleteFolderRecursively(arch, newpath);
newpath = path + dir.entry(i);
FSUSER_DeleteDirectory(arch, fsMakePath(PATH_UTF16, newpath.data()));
}
else
{
else {
std::u16string newpath = path + dir.entry(i);
FSUSER_DeleteFile(arch, fsMakePath(PATH_UTF16, newpath.data()));
}
@ -165,324 +150,280 @@ Result io::deleteFolderRecursively(FS_Archive arch, const std::u16string& path)
void io::backup(size_t index)
{
// check if multiple selection is enabled and don't ask for confirmation if that's the case
if (!MS::multipleSelectionEnabled())
{
if (!Gui::askForConfirmation("Backup selected save?"))
{
if (!MS::multipleSelectionEnabled()) {
if (!Gui::askForConfirmation("Backup selected save?")) {
return;
}
}
const Mode_t mode = Archive::mode();
const Mode_t mode = Archive::mode();
const size_t cellIndex = Gui::scrollableIndex();
const bool isNewFolder = cellIndex == 0;
Result res = 0;
Result res = 0;
Title title;
getTitle(title, index);
if (title.cardType() == CARD_CTR)
{
if (title.cardType() == CARD_CTR) {
FS_Archive archive;
if (mode == MODE_SAVE)
{
if (mode == MODE_SAVE) {
res = Archive::save(&archive, title.mediaType(), title.lowId(), title.highId());
}
else if (mode == MODE_EXTDATA)
{
else if (mode == MODE_EXTDATA) {
res = Archive::extdata(&archive, title.extdataId());
}
if (R_SUCCEEDED(res))
{
if (R_SUCCEEDED(res)) {
std::string suggestion = DateTime::dateTimeStr();
std::u16string customPath;
if (MS::multipleSelectionEnabled())
{
if (MS::multipleSelectionEnabled()) {
customPath = isNewFolder ? StringUtils::UTF8toUTF16(suggestion.c_str()) : StringUtils::UTF8toUTF16("");
}
else
{
customPath = isNewFolder ? StringUtils::removeForbiddenCharacters(KeyboardManager::get().keyboard(suggestion))
: StringUtils::UTF8toUTF16("");
else {
customPath =
isNewFolder ? StringUtils::removeForbiddenCharacters(KeyboardManager::get().keyboard(suggestion)) : StringUtils::UTF8toUTF16("");
}
std::u16string dstPath;
if (!isNewFolder)
{
if (!isNewFolder) {
// we're overriding an existing folder
dstPath = mode == MODE_SAVE ? title.fullSavePath(cellIndex) : title.fullExtdataPath(cellIndex);
}
else
{
else {
dstPath = mode == MODE_SAVE ? title.savePath() : title.extdataPath();
dstPath += StringUtils::UTF8toUTF16("/") + customPath;
}
if (!isNewFolder || io::directoryExists(Archive::sdmc(), dstPath))
{
}
if (!isNewFolder || io::directoryExists(Archive::sdmc(), dstPath)) {
res = FSUSER_DeleteDirectoryRecursively(Archive::sdmc(), fsMakePath(PATH_UTF16, dstPath.data()));
if (R_FAILED(res))
{
if (R_FAILED(res)) {
FSUSER_CloseArchive(archive);
Gui::showError(res, "Failed to delete the existing backup\ndirectory recursively.");
return;
}
}
res = io::createDirectory(Archive::sdmc(), dstPath);
if (R_FAILED(res))
{
if (R_FAILED(res)) {
FSUSER_CloseArchive(archive);
Gui::showError(res, "Failed to create destination directory.");
return;
}
std::u16string copyPath = dstPath + StringUtils::UTF8toUTF16("/");
res = io::copyDirectory(archive, Archive::sdmc(), StringUtils::UTF8toUTF16("/"), copyPath);
if (R_FAILED(res))
{
if (R_FAILED(res)) {
std::string message = mode == MODE_SAVE ? "Failed to backup save." : "Failed to backup extdata.";
FSUSER_CloseArchive(archive);
Gui::showError(res, message);
FSUSER_DeleteDirectoryRecursively(Archive::sdmc(), fsMakePath(PATH_UTF16, dstPath.data()));
return;
}
refreshDirectories(title.id());
}
else
{
else {
Gui::showError(res, "Failed to open save archive.");
}
FSUSER_CloseArchive(archive);
FSUSER_CloseArchive(archive);
}
else
{
else {
CardType cardType = title.SPICardType();
u32 saveSize = SPIGetCapacity(cardType);
u32 sectorSize = (saveSize < 0x10000) ? saveSize : 0x10000;
u32 saveSize = SPIGetCapacity(cardType);
u32 sectorSize = (saveSize < 0x10000) ? saveSize : 0x10000;
std::string suggestion = DateTime::dateTimeStr();
std::u16string customPath;
if (MS::multipleSelectionEnabled())
{
if (MS::multipleSelectionEnabled()) {
customPath = isNewFolder ? StringUtils::UTF8toUTF16(suggestion.c_str()) : StringUtils::UTF8toUTF16("");
}
else
{
else {
customPath = isNewFolder ? KeyboardManager::get().keyboard(suggestion) : StringUtils::UTF8toUTF16("");
}
std::u16string dstPath;
if (!isNewFolder)
{
if (!isNewFolder) {
// we're overriding an existing folder
dstPath = mode == MODE_SAVE ? title.fullSavePath(cellIndex) : title.fullExtdataPath(cellIndex);
}
else
{
else {
dstPath = mode == MODE_SAVE ? title.savePath() : title.extdataPath();
dstPath += StringUtils::UTF8toUTF16("/") + customPath;
}
if (!isNewFolder || io::directoryExists(Archive::sdmc(), dstPath))
{
}
if (!isNewFolder || io::directoryExists(Archive::sdmc(), dstPath)) {
res = FSUSER_DeleteDirectoryRecursively(Archive::sdmc(), fsMakePath(PATH_UTF16, dstPath.data()));
if (R_FAILED(res))
{
if (R_FAILED(res)) {
Gui::showError(res, "Failed to delete the existing\nbackup directory recursively.");
return;
}
}
res = io::createDirectory(Archive::sdmc(), dstPath);
if (R_FAILED(res))
{
if (R_FAILED(res)) {
Gui::showError(res, "Failed to create destination directory.");
return;
}
std::u16string copyPath = dstPath + StringUtils::UTF8toUTF16("/") + StringUtils::UTF8toUTF16(title.shortDescription().c_str()) + StringUtils::UTF8toUTF16(".sav");
std::u16string copyPath =
dstPath + StringUtils::UTF8toUTF16("/") + StringUtils::UTF8toUTF16(title.shortDescription().c_str()) + StringUtils::UTF8toUTF16(".sav");
u8* saveFile = new u8[saveSize];
for (u32 i = 0; i < saveSize/sectorSize; ++i)
{
res = SPIReadSaveData(cardType, sectorSize*i, saveFile + sectorSize*i, sectorSize);
if (R_FAILED(res))
{
for (u32 i = 0; i < saveSize / sectorSize; ++i) {
res = SPIReadSaveData(cardType, sectorSize * i, saveFile + sectorSize * i, sectorSize);
if (R_FAILED(res)) {
break;
}
Gui::drawCopy(StringUtils::UTF8toUTF16(title.shortDescription().c_str()) + StringUtils::UTF8toUTF16(".sav"), sectorSize*(i+1), saveSize);
Gui::drawCopy(
StringUtils::UTF8toUTF16(title.shortDescription().c_str()) + StringUtils::UTF8toUTF16(".sav"), sectorSize * (i + 1), saveSize);
}
if (R_FAILED(res))
{
if (R_FAILED(res)) {
delete[] saveFile;
Gui::showError(res, "Failed to backup save.");
FSUSER_DeleteDirectoryRecursively(Archive::sdmc(), fsMakePath(PATH_UTF16, dstPath.data()));
return;
}
FSStream stream(Archive::sdmc(), copyPath, FS_OPEN_WRITE, saveSize);
if (stream.good())
{
if (stream.good()) {
stream.write(saveFile, saveSize);
}
else
{
else {
delete[] saveFile;
stream.close();
Gui::showError(res, "Failed to backup save.");
FSUSER_DeleteDirectoryRecursively(Archive::sdmc(), fsMakePath(PATH_UTF16, dstPath.data()));
return;
return;
}
delete[] saveFile;
stream.close();
refreshDirectories(title.id());
}
Gui::showInfo("Progress correctly saved to disk.");
}
void io::restore(size_t index)
{
const Mode_t mode = Archive::mode();
const Mode_t mode = Archive::mode();
const size_t cellIndex = Gui::scrollableIndex();
if (cellIndex == 0 || !Gui::askForConfirmation("Restore selected save?"))
{
if (cellIndex == 0 || !Gui::askForConfirmation("Restore selected save?")) {
return;
}
Result res = 0;
Title title;
getTitle(title, index);
if (title.cardType() == CARD_CTR)
{
if (title.cardType() == CARD_CTR) {
FS_Archive archive;
if (mode == MODE_SAVE)
{
if (mode == MODE_SAVE) {
res = Archive::save(&archive, title.mediaType(), title.lowId(), title.highId());
}
else if (mode == MODE_EXTDATA)
{
else if (mode == MODE_EXTDATA) {
res = Archive::extdata(&archive, title.extdataId());
}
if (R_SUCCEEDED(res))
{
if (R_SUCCEEDED(res)) {
std::u16string srcPath = mode == MODE_SAVE ? title.fullSavePath(cellIndex) : title.fullExtdataPath(cellIndex);
srcPath += StringUtils::UTF8toUTF16("/");
std::u16string dstPath = StringUtils::UTF8toUTF16("/");
if (mode != MODE_EXTDATA)
{
if (mode != MODE_EXTDATA) {
res = FSUSER_DeleteDirectoryRecursively(archive, fsMakePath(PATH_UTF16, dstPath.data()));
}
else
{
else {
res = deleteFolderRecursively(archive, dstPath);
}
res = io::copyDirectory(Archive::sdmc(), archive, srcPath, dstPath);
if (R_FAILED(res))
{
if (R_FAILED(res)) {
std::string message = mode == MODE_SAVE ? "Failed to restore save." : "Failed to restore extdata.";
FSUSER_CloseArchive(archive);
Gui::showError(res, message);
return;
}
if (mode == MODE_SAVE)
{
if (mode == MODE_SAVE) {
res = FSUSER_ControlArchive(archive, ARCHIVE_ACTION_COMMIT_SAVE_DATA, NULL, 0, NULL, 0);
if (R_FAILED(res))
{
if (R_FAILED(res)) {
FSUSER_CloseArchive(archive);
Gui::showError(res, "Failed to commit save data.");
return;
return;
}
u8 out;
u64 secureValue = ((u64)SECUREVALUE_SLOT_SD << 32) | (title.uniqueId() << 8);
res = FSUSER_ControlSecureSave(SECURESAVE_ACTION_DELETE, &secureValue, 8, &out, 1);
if (R_FAILED(res))
{
res = FSUSER_ControlSecureSave(SECURESAVE_ACTION_DELETE, &secureValue, 8, &out, 1);
if (R_FAILED(res)) {
FSUSER_CloseArchive(archive);
Gui::showError(res, "Failed to fix secure value.");
return;
return;
}
}
}
else
{
else {
Gui::showError(res, "Failed to open save archive.");
}
FSUSER_CloseArchive(archive);
FSUSER_CloseArchive(archive);
}
else
{
else {
CardType cardType = title.SPICardType();
u32 saveSize = SPIGetCapacity(cardType);
u32 pageSize = SPIGetPageSize(cardType);
u32 saveSize = SPIGetCapacity(cardType);
u32 pageSize = SPIGetPageSize(cardType);
std::u16string srcPath = title.fullSavePath(cellIndex);
srcPath += StringUtils::UTF8toUTF16("/") + StringUtils::UTF8toUTF16(title.shortDescription().c_str()) + StringUtils::UTF8toUTF16(".sav");
u8* saveFile = new u8[saveSize];
FSStream stream(Archive::sdmc(), srcPath, FS_OPEN_READ);
if (stream.good())
{
if (stream.good()) {
stream.read(saveFile, saveSize);
}
res = stream.result();
stream.close();
if (R_FAILED(res))
{
if (R_FAILED(res)) {
delete[] saveFile;
Gui::showError(res, "Failed to read save file backup.");
return;
}
for (u32 i = 0; i < saveSize/pageSize; ++i)
{
res = SPIWriteSaveData(cardType, pageSize*i, saveFile + pageSize*i, pageSize);
if (R_FAILED(res))
{
for (u32 i = 0; i < saveSize / pageSize; ++i) {
res = SPIWriteSaveData(cardType, pageSize * i, saveFile + pageSize * i, pageSize);
if (R_FAILED(res)) {
break;
}
Gui::drawCopy(StringUtils::UTF8toUTF16(title.shortDescription().c_str()) + StringUtils::UTF8toUTF16(".sav"), pageSize*(i+1), saveSize);
Gui::drawCopy(
StringUtils::UTF8toUTF16(title.shortDescription().c_str()) + StringUtils::UTF8toUTF16(".sav"), pageSize * (i + 1), saveSize);
}
if (R_FAILED(res))
{
if (R_FAILED(res)) {
delete[] saveFile;
Gui::showError(res, "Failed to restore save.");
return;
}
}
delete[] saveFile;
}
Gui::showInfo(Gui::nameFromCell(cellIndex) + "\nhas been restored successfully.");
}
void io::deleteBackupFolder(const std::u16string& path)
{
Result res = FSUSER_DeleteDirectoryRecursively(Archive::sdmc(), fsMakePath(PATH_UTF16, path.data()));
if (R_FAILED(res))
{
if (R_FAILED(res)) {
Gui::showError(res, "Failed to delete backup folder.");
}
}

View file

@ -1,41 +1,42 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "main.hpp"
#include "thread.hpp"
#include "util.hpp"
int main() {
int main()
{
if (R_FAILED(servicesInit())) {
servicesExit();
return -1;
}
int selectionTimer = 0;
int refreshTimer = 0;
int refreshTimer = 0;
Threads::create((ThreadFunc)Threads::titles);
u32 kHeld, kDown = hidKeysDown();
@ -50,49 +51,39 @@ int main() {
// Backup list active: Backup/Restore
// Backup list inactive: Activate backup list only if multiple
// selections are enabled
if (kDown & KEY_A)
{
if (kDown & KEY_A) {
// If backup list is active...
if (g_bottomScrollEnabled)
{
if (g_bottomScrollEnabled) {
// If the "New..." entry is selected...
if (0 == Gui::scrollableIndex())
{
if (0 == Gui::scrollableIndex()) {
io::backup(Gui::index());
}
else
{
else {
io::restore(Gui::index());
}
}
else
{
else {
// Activate backup list only if multiple selections are not enabled
if (!MS::multipleSelectionEnabled())
{
if (!MS::multipleSelectionEnabled()) {
g_bottomScrollEnabled = true;
Gui::updateButtons();
}
}
}
if (kDown & KEY_B)
{
if (kDown & KEY_B) {
g_bottomScrollEnabled = false;
MS::clearSelectedEntries();
Gui::resetScrollableIndex();
Gui::updateButtons();
}
if (kDown & KEY_X)
{
if (g_bottomScrollEnabled)
{
if (kDown & KEY_X) {
if (g_bottomScrollEnabled) {
bool isSaveMode = Archive::mode() == MODE_SAVE;
size_t index = Gui::scrollableIndex();
size_t index = Gui::scrollableIndex();
// avoid actions if X is pressed on "New..."
if (index > 0 && Gui::askForConfirmation("Delete selected backup?"))
{
if (index > 0 && Gui::askForConfirmation("Delete selected backup?")) {
Title title;
getTitle(title, Gui::index());
std::u16string path = isSaveMode ? title.fullSavePath(index) : title.fullExtdataPath(index);
@ -101,8 +92,7 @@ int main() {
Gui::scrollableIndex(index - 1);
}
}
else
{
else {
Gui::resetIndex();
Archive::mode(Archive::mode() == MODE_SAVE ? MODE_EXTDATA : MODE_SAVE);
MS::clearSelectedEntries();
@ -110,10 +100,8 @@ int main() {
}
}
if (kDown & KEY_Y)
{
if (g_bottomScrollEnabled)
{
if (kDown & KEY_Y) {
if (g_bottomScrollEnabled) {
Gui::resetScrollableIndex();
g_bottomScrollEnabled = false;
}
@ -121,36 +109,29 @@ int main() {
Gui::updateButtons(); // Do this last
}
if (kHeld & KEY_Y)
{
if (kHeld & KEY_Y) {
selectionTimer++;
}
else
{
else {
selectionTimer = 0;
}
if (selectionTimer > 90)
{
if (selectionTimer > 90) {
MS::clearSelectedEntries();
for (size_t i = 0, sz = getTitleCount(); i < sz; i++)
{
for (size_t i = 0, sz = getTitleCount(); i < sz; i++) {
MS::addSelectedEntry(i);
}
selectionTimer = 0;
}
if (kHeld & KEY_B)
{
if (kHeld & KEY_B) {
refreshTimer++;
}
else
{
else {
refreshTimer = 0;
}
if (refreshTimer > 90)
{
if (refreshTimer > 90) {
Gui::resetIndex();
MS::clearSelectedEntries();
Gui::resetScrollableIndex();
@ -158,75 +139,58 @@ int main() {
refreshTimer = 0;
}
if (Gui::isBackupReleased() || (kDown & KEY_L))
{
if (MS::multipleSelectionEnabled())
{
if (Gui::isBackupReleased() || (kDown & KEY_L)) {
if (MS::multipleSelectionEnabled()) {
Gui::resetScrollableIndex();
std::vector<size_t> list = MS::selectedEntries();
for (size_t i = 0, sz = list.size(); i < sz; i++)
{
for (size_t i = 0, sz = list.size(); i < sz; i++) {
io::backup(list.at(i));
}
MS::clearSelectedEntries();
Gui::updateButtons();
}
else if (g_bottomScrollEnabled)
{
else if (g_bottomScrollEnabled) {
io::backup(Gui::index());
}
}
if (Gui::isRestoreReleased() || (kDown & KEY_R))
{
if (MS::multipleSelectionEnabled())
{
if (Gui::isRestoreReleased() || (kDown & KEY_R)) {
if (MS::multipleSelectionEnabled()) {
MS::clearSelectedEntries();
Gui::updateButtons();
}
else if (g_bottomScrollEnabled)
{
else if (g_bottomScrollEnabled) {
io::restore(Gui::index());
}
}
if (getTitleCount() > 0)
{
if (getTitleCount() > 0) {
Title title;
getTitle(title, Gui::index());
if (title.isActivityLog())
{
if (Gui::isPlayCoinsReleased())
{
if (!Archive::setPlayCoins())
{
if (title.isActivityLog()) {
if (Gui::isPlayCoinsReleased()) {
if (!Archive::setPlayCoins()) {
Gui::showError(-1, "Failed to set play coins.");
}
}
}
else
{
if (Gui::isCheatReleased() && CheatManager::loaded())
{
if (MS::multipleSelectionEnabled())
{
else {
if (Gui::isCheatReleased() && CheatManager::loaded()) {
if (MS::multipleSelectionEnabled()) {
MS::clearSelectedEntries();
Gui::updateButtons();
}
else
{
else {
Title title;
getTitle(title, Gui::index());
std::string key = StringUtils::format("%016llX", title.id());
if (CheatManager::availableCodes(key))
{
if (CheatManager::availableCodes(key)) {
CheatManager::manageCheats(key);
}
else
{
else {
Gui::showInfo("No available cheat codes for this title.");
}
}
}
}
}
}

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "scrollable.hpp"
@ -46,7 +46,7 @@ void Scrollable::resetIndex(void)
void Scrollable::push_back(u32 color, u32 colorMessage, const std::string& message, bool selected)
{
const float spacing = mh / mVisibleEntries;
Clickable* cell = new Clickable(mx, my + (size() % mVisibleEntries)*spacing, mw, spacing, color, colorMessage, message, false);
Clickable* cell = new Clickable(mx, my + (size() % mVisibleEntries) * spacing, mw, spacing, color, colorMessage, message, false);
cell->selected(selected);
mCells.push_back(cell);
}
@ -57,23 +57,21 @@ void Scrollable::updateSelection(void)
hidTouchRead(&touch);
const u32 hu = (mHid->maxEntries(size()) + 1) * mh / mVisibleEntries;
if (hidKeysHeld() & KEY_TOUCH && touch.py > (float)my && touch.py < (float)(my+hu) && touch.px > (float)mx && touch.px < (float)(mx+mw))
{
mHid->index((size_t)((touch.py - my)*mVisibleEntries/mh));
if (hidKeysHeld() & KEY_TOUCH && touch.py > (float)my && touch.py < (float)(my + hu) && touch.px > (float)mx && touch.px < (float)(mx + mw)) {
mHid->index((size_t)((touch.py - my) * mVisibleEntries / mh));
}
mHid->update(size());
mIndex = mHid->index();
mPage = mHid->page();
mPage = mHid->page();
}
void Scrollable::draw(bool condition)
{
const size_t baseIndex = mVisibleEntries*mPage;
const size_t sz = size() - baseIndex > mVisibleEntries ? mVisibleEntries : size() - baseIndex;
for (size_t i = baseIndex; i < baseIndex + sz; i++)
{
const size_t baseIndex = mVisibleEntries * mPage;
const size_t sz = size() - baseIndex > mVisibleEntries ? mVisibleEntries : size() - baseIndex;
for (size_t i = baseIndex; i < baseIndex + sz; i++) {
mCells.at(i)->draw(0.5f, 0);
}
@ -82,10 +80,8 @@ void Scrollable::draw(bool condition)
C2D_DrawRectSolid(mx, my + sz * rowHeight, 0.5f, mw, rowHeight * blankRows, COLOR_GREY_DARKER);
// draw selector
for (size_t i = baseIndex; i < baseIndex + sz; i++)
{
if (mCells.at(i)->selected())
{
for (size_t i = baseIndex; i < baseIndex + sz; i++) {
if (mCells.at(i)->selected()) {
mCells.at(i)->drawOutline(condition ? COLOR_BLUE : COLOR_GREY_LIGHT);
break;
}

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "smdh.hpp"
@ -30,21 +30,19 @@ smdh_s* loadSMDH(u32 low, u32 high, u8 media)
{
Handle fileHandle;
u32 archPath[] = {low, high, media, 0x0};
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};
Result res = FSUSER_OpenFileDirectly(&fileHandle, ARCHIVE_SAVEDATA_AND_CONTENT, binArchPath, binFilePath, FS_OPEN_READ, 0);
if (R_SUCCEEDED(res))
{
if (R_SUCCEEDED(res)) {
u32 read;
FSFILE_Read(fileHandle, &read, 0, smdh, sizeof(smdh_s));
}
else
{
else {
delete smdh;
smdh = NULL;
}
@ -56,8 +54,7 @@ smdh_s* loadSMDH(u32 low, u32 high, u8 media)
smdh_s* loadSMDH(const std::string& path)
{
FILE* f = fopen(path.c_str(), "rb");
if (f != NULL)
{
if (f != NULL) {
smdh_s* smdh = new smdh_s;
fread(smdh, 1, sizeof(smdh_s), f);
fclose(f);

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
/*
* This file is part of TWLSaveTool.
@ -41,7 +41,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#include "spi.hpp"
u8* fill_buf = NULL;
@ -49,17 +49,17 @@ u8* fill_buf = NULL;
Result SPIWriteRead(CardType type, void* cmd, u32 cmdSize, void* answer, u32 answerSize, void* data, u32 dataSize)
{
u8 transferOp = pxiDevMakeTransferOption(BAUDRATE_4MHZ, BUSMODE_1BIT), transferOp2 = pxiDevMakeTransferOption(BAUDRATE_1MHZ, BUSMODE_1BIT);
u64 waitOp = pxiDevMakeWaitOperation(WAIT_NONE, DEASSERT_NONE, 0LL);
u64 waitOp = pxiDevMakeWaitOperation(WAIT_NONE, DEASSERT_NONE, 0LL);
u64 headerFooterVal = 0;
bool b = type == FLASH_512KB_INFRARED || type == FLASH_256KB_INFRARED;
bool b = type == FLASH_512KB_INFRARED || type == FLASH_256KB_INFRARED;
PXIDEV_SPIBuffer headerBuffer = {&headerFooterVal, (b) ? 1U : 0U, (b) ? transferOp2 : transferOp, waitOp};
PXIDEV_SPIBuffer cmdBuffer = {cmd, cmdSize, transferOp, waitOp};
PXIDEV_SPIBuffer answerBuffer = {answer, answerSize, transferOp, waitOp};
PXIDEV_SPIBuffer dataBuffer = {data, dataSize, transferOp, waitOp};
PXIDEV_SPIBuffer nullBuffer = {NULL, 0U, transferOp, waitOp};
PXIDEV_SPIBuffer footerBuffer = {&headerFooterVal, 0U, transferOp, waitOp};
PXIDEV_SPIBuffer headerBuffer = { &headerFooterVal, (b) ? 1U : 0U, (b) ? transferOp2 : transferOp, waitOp };
PXIDEV_SPIBuffer cmdBuffer = { cmd, cmdSize, transferOp, waitOp };
PXIDEV_SPIBuffer answerBuffer = { answer, answerSize, transferOp, waitOp };
PXIDEV_SPIBuffer dataBuffer = { data, dataSize, transferOp, waitOp };
PXIDEV_SPIBuffer nullBuffer = { NULL, 0U, transferOp, waitOp };
PXIDEV_SPIBuffer footerBuffer = { &headerFooterVal, 0U, transferOp, waitOp };
return PXIDEV_SPIMultiWriteRead(&headerBuffer, &cmdBuffer, &answerBuffer, &dataBuffer, &nullBuffer, &footerBuffer);
}
@ -67,13 +67,14 @@ Result SPIWaitWriteEnd(CardType type)
{
u8 cmd = SPI_CMD_RDSR, statusReg = 0;
Result res = 0;
int panic = 0;
int panic = 0;
do {
panic++;
res = SPIWriteRead(type, &cmd, 1, &statusReg, 1, 0, 0);
if (res) return res;
if (res)
return res;
} while (statusReg & SPI_FLG_WIP && panic < 1000);
return panic >= 1000 ? 1 : 0;
}
@ -82,93 +83,106 @@ Result SPIEnableWriting(CardType type)
u8 cmd = SPI_CMD_WREN, statusReg = 0;
Result res = SPIWriteRead(type, &cmd, 1, NULL, 0, 0, 0);
if (res || type == EEPROM_512B) return res; // Weird, but works (otherwise we're getting an infinite loop for that chip type).
if (res || type == EEPROM_512B)
return res; // Weird, but works (otherwise we're getting an infinite loop for that chip type).
cmd = SPI_CMD_RDSR;
do {
res = SPIWriteRead(type, &cmd, 1, &statusReg, 1, 0, 0);
if (res) return res;
} while(statusReg & ~SPI_FLG_WEL);
if (res)
return res;
} while (statusReg & ~SPI_FLG_WEL);
return 0;
}
Result SPIReadJEDECIDAndStatusReg(CardType type, u32* id, u8* statusReg)
{
u8 cmd = SPI_FLASH_CMD_RDID;
u8 reg = 0;
u8 idbuf[3] = { 0 };
u32 id_ = 0;
Result res = SPIWaitWriteEnd(type);
if (res) return res;
if ((res = SPIWriteRead(type, &cmd, 1, idbuf, 3, 0, 0))) return res;
u8 cmd = SPI_FLASH_CMD_RDID;
u8 reg = 0;
u8 idbuf[3] = {0};
u32 id_ = 0;
Result res = SPIWaitWriteEnd(type);
if (res)
return res;
if ((res = SPIWriteRead(type, &cmd, 1, idbuf, 3, 0, 0)))
return res;
id_ = (idbuf[0] << 16) | (idbuf[1] << 8) | idbuf[2];
cmd = SPI_CMD_RDSR;
if ((res = SPIWriteRead(type, &cmd, 1, &reg, 1, 0, 0))) return res;
if (id) *id = id_;
if (statusReg) *statusReg = reg;
if ((res = SPIWriteRead(type, &cmd, 1, &reg, 1, 0, 0)))
return res;
if (id)
*id = id_;
if (statusReg)
*statusReg = reg;
return 0;
}
u32 SPIGetPageSize(CardType type)
{
u32 EEPROMSizes[] = { 16, 32, 128, 256 };
if (type == NO_CHIP || type > CHIP_LAST) return 0;
else if (type < FLASH_256KB_1) return EEPROMSizes[(int) type];
else return 256;
u32 EEPROMSizes[] = {16, 32, 128, 256};
if (type == NO_CHIP || type > CHIP_LAST)
return 0;
else if (type < FLASH_256KB_1)
return EEPROMSizes[(int)type];
else
return 256;
}
u32 SPIGetCapacity(CardType type)
{
u32 sz[] = { 9, 13, 16, 17, 18, 18, 19, 19, 20, 23, 19, 19 };
if (type == NO_CHIP || type > CHIP_LAST) return 0;
else return 1 << sz[(int) type];
u32 sz[] = {9, 13, 16, 17, 18, 18, 19, 19, 20, 23, 19, 19};
if (type == NO_CHIP || type > CHIP_LAST)
return 0;
else
return 1 << sz[(int)type];
}
Result SPIWriteSaveData(CardType type, u32 offset, void* data, u32 size)
{
u8 cmd[4] = { 0 };
u8 cmd[4] = {0};
u32 cmdSize = 4;
u32 end = offset + size;
u32 pos = offset;
if (size == 0) return 0;
if (size == 0)
return 0;
u32 pageSize = SPIGetPageSize(type);
if (pageSize == 0) return 0xC8E13404;
Result res = SPIWaitWriteEnd(type);
if (res) return res;
size = (size <= SPIGetCapacity(type) - offset) ? size : SPIGetCapacity(type) - offset;
if (pageSize == 0)
return 0xC8E13404;
while(pos < end)
{
switch(type)
{
Result res = SPIWaitWriteEnd(type);
if (res)
return res;
size = (size <= SPIGetCapacity(type) - offset) ? size : SPIGetCapacity(type) - offset;
while (pos < end) {
switch (type) {
case EEPROM_512B:
cmdSize = 2;
cmd[0] = (pos >= 0x100) ? SPI_512B_EEPROM_CMD_WRHI : SPI_512B_EEPROM_CMD_WRLO;
cmd[1] = (u8) pos;
cmd[0] = (pos >= 0x100) ? SPI_512B_EEPROM_CMD_WRHI : SPI_512B_EEPROM_CMD_WRLO;
cmd[1] = (u8)pos;
break;
case EEPROM_8KB:
case EEPROM_64KB:
cmdSize = 3;
cmd[0] = SPI_EEPROM_CMD_WRITE;
cmd[1] = (u8)(pos >> 8);
cmd[2] = (u8) pos;
cmd[0] = SPI_EEPROM_CMD_WRITE;
cmd[1] = (u8)(pos >> 8);
cmd[2] = (u8)pos;
break;
case EEPROM_128KB:
cmdSize = 4;
cmd[0] = SPI_EEPROM_CMD_WRITE;
cmd[1] = (u8)(pos >> 16);
cmd[2] = (u8)(pos >> 8);
cmd[3] = (u8) pos;
cmd[0] = SPI_EEPROM_CMD_WRITE;
cmd[1] = (u8)(pos >> 16);
cmd[2] = (u8)(pos >> 8);
cmd[3] = (u8)pos;
break;
case FLASH_256KB_1:
case FLASH_256KB_2:
@ -178,94 +192,99 @@ Result SPIWriteSaveData(CardType type, u32 offset, void* data, u32 size)
case FLASH_512KB_INFRARED:
case FLASH_256KB_INFRARED:
cmdSize = 4;
cmd[0] = SPI_FLASH_CMD_PW;
cmd[1] = (u8)(pos >> 16);
cmd[2] = (u8)(pos >> 8);
cmd[3] = (u8) pos;
cmd[0] = SPI_FLASH_CMD_PW;
cmd[1] = (u8)(pos >> 16);
cmd[2] = (u8)(pos >> 8);
cmd[3] = (u8)pos;
break;
case FLASH_8MB:
return 0xC8E13404; // writing is unsupported (so is reading? need to test)
default:
return 0; // never happens
}
u32 remaining = end - pos;
u32 nb = pageSize - (pos % pageSize);
u32 nb = pageSize - (pos % pageSize);
u32 dataSize = (remaining < nb) ? remaining : nb;
if ( (res = SPIEnableWriting(type)) ) return res;
if ( (res = SPIWriteRead(type, cmd, cmdSize, NULL, 0, (void*) ((u8*) data - offset + pos), dataSize)) ) return res;
if ( (res = SPIWaitWriteEnd(type)) ) return res;
if ((res = SPIEnableWriting(type)))
return res;
if ((res = SPIWriteRead(type, cmd, cmdSize, NULL, 0, (void*)((u8*)data - offset + pos), dataSize)))
return res;
if ((res = SPIWaitWriteEnd(type)))
return res;
pos = ((pos / pageSize) + 1) * pageSize; // truncate
}
return 0;
}
Result _SPIReadSaveData_512B_impl(u32 pos, void* data, u32 size)
{
{
u8 cmd[4];
u32 cmdSize = 2;
u32 end = pos + size;
u32 read = 0;
if (pos < 0x100)
{
if (pos < 0x100) {
u32 len = 0x100 - pos;
cmd[0] = SPI_512B_EEPROM_CMD_RDLO;
cmd[1] = (u8) pos;
cmd[0] = SPI_512B_EEPROM_CMD_RDLO;
cmd[1] = (u8)pos;
Result res = SPIWriteRead(EEPROM_512B, cmd, cmdSize, data, len, NULL, 0);
if (res) return res;
if (res)
return res;
read += len;
}
if (end >= 0x100)
{
if (end >= 0x100) {
u32 len = end - 0x100;
cmd[0] = SPI_512B_EEPROM_CMD_RDHI;
cmd[1] = (u8)(pos + read);
Result res = SPIWriteRead(EEPROM_512B, cmd, cmdSize, (void*)((u8*)data + read), len, NULL, 0);
if (res) return res;
if (res)
return res;
}
return 0;
}
Result SPIReadSaveData(CardType type, u32 offset, void* data, u32 size)
{
u8 cmd[4] = { SPI_CMD_READ };
{
u8 cmd[4] = {SPI_CMD_READ};
u32 cmdSize = 4;
if (size == 0) return 0;
if (type == NO_CHIP) return 0xC8E13404;
if (size == 0)
return 0;
if (type == NO_CHIP)
return 0xC8E13404;
Result res = SPIWaitWriteEnd(type);
if (res) return res;
size = (size <= SPIGetCapacity(type) - offset) ? size : SPIGetCapacity(type) - offset;
if (res)
return res;
size = (size <= SPIGetCapacity(type) - offset) ? size : SPIGetCapacity(type) - offset;
u32 pos = offset;
switch(type)
{
switch (type) {
case EEPROM_512B:
return _SPIReadSaveData_512B_impl(offset, data, size);
break;
case EEPROM_8KB:
case EEPROM_64KB:
cmdSize = 3;
cmd[1] = (u8)(pos >> 8);
cmd[2] = (u8) pos;
cmd[1] = (u8)(pos >> 8);
cmd[2] = (u8)pos;
break;
case EEPROM_128KB:
cmdSize = 4;
cmd[1] = (u8)(pos >> 16);
cmd[2] = (u8)(pos >> 8);
cmd[3] = (u8) pos;
cmd[1] = (u8)(pos >> 16);
cmd[2] = (u8)(pos >> 8);
cmd[3] = (u8)pos;
break;
case FLASH_256KB_1:
case FLASH_256KB_2:
@ -276,40 +295,41 @@ Result SPIReadSaveData(CardType type, u32 offset, void* data, u32 size)
case FLASH_512KB_INFRARED:
case FLASH_256KB_INFRARED:
cmdSize = 4;
cmd[1] = (u8)(pos >> 16);
cmd[2] = (u8)(pos >> 8);
cmd[3] = (u8) pos;
cmd[1] = (u8)(pos >> 16);
cmd[2] = (u8)(pos >> 8);
cmd[3] = (u8)pos;
break;
default:
return 0; // never happens
}
return SPIWriteRead(type, cmd, cmdSize, data, size, NULL, 0);
}
Result SPIEraseSector(CardType type, u32 offset)
{
u8 cmd[4] = { SPI_FLASH_CMD_SE, (u8)(offset >> 16), (u8)(offset >> 8), (u8) offset };
if (type == NO_CHIP || type == FLASH_8MB) return 0xC8E13404;
if (type < FLASH_256KB_1 && fill_buf == NULL)
{
u8 cmd[4] = {SPI_FLASH_CMD_SE, (u8)(offset >> 16), (u8)(offset >> 8), (u8)offset};
if (type == NO_CHIP || type == FLASH_8MB)
return 0xC8E13404;
if (type < FLASH_256KB_1 && fill_buf == NULL) {
fill_buf = new u8[0x10000];
memset(fill_buf, 0xff, 0x10000);
}
Result res = SPIWaitWriteEnd(type);
if (type >= FLASH_256KB_1)
{
if ( (res = SPIEnableWriting(type)) ) return res;
if ( (res = SPIWriteRead(type, cmd, 4, NULL, 0, NULL, 0)) ) return res;
if ( (res = SPIWaitWriteEnd(type)) ) return res;
if (type >= FLASH_256KB_1) {
if ((res = SPIEnableWriting(type)))
return res;
if ((res = SPIWriteRead(type, cmd, 4, NULL, 0, NULL, 0)))
return res;
if ((res = SPIWaitWriteEnd(type)))
return res;
}
// Simulate the same behavior on EEPROM chips.
else
{
u32 sz = SPIGetCapacity(type);
else {
u32 sz = SPIGetCapacity(type);
Result res = SPIWriteSaveData(type, 0, fill_buf, (sz < 0x10000) ? sz : 0x10000);
return res;
}
@ -328,123 +348,144 @@ Result SPIEraseSector(CardType type, u32 offset)
*
* Copyright (C) Pokedoc (2010)
*/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
Result _SPIIsDataMirrored(CardType type, int size, bool* mirrored)
{
u32 offset0 = (size-1); // n KB
u32 offset1 = (2*size-1); // 2n KB
u8 buf1; // +0k data read -> write
u8 buf2; // +n k data read -> read
u8 buf3; // +0k ~data write
u8 buf4; // +n k data new comp buf2
u32 offset0 = (size - 1); // n KB
u32 offset1 = (2 * size - 1); // 2n KB
u8 buf1; // +0k data read -> write
u8 buf2; // +n k data read -> read
u8 buf3; // +0k ~data write
u8 buf4; // +n k data new comp buf2
Result res;
if ( (res = SPIReadSaveData(type, offset0, &buf1, 1)) ) return res;
if ( (res = SPIReadSaveData(type, offset1, &buf2, 1)) ) return res;
buf3=~buf1;
if ( (res = SPIWriteSaveData(type, offset0, &buf3, 1)) ) return res;
if ( (res = SPIReadSaveData(type, offset1, &buf4, 1)) ) return res;
if ( (res = SPIWriteSaveData(type, offset0, &buf1, 1)) ) return res;
if ((res = SPIReadSaveData(type, offset0, &buf1, 1)))
return res;
if ((res = SPIReadSaveData(type, offset1, &buf2, 1)))
return res;
buf3 = ~buf1;
if ((res = SPIWriteSaveData(type, offset0, &buf3, 1)))
return res;
if ((res = SPIReadSaveData(type, offset1, &buf4, 1)))
return res;
if ((res = SPIWriteSaveData(type, offset0, &buf1, 1)))
return res;
*mirrored = buf2 != buf4;
return 0;
}
Result SPIGetCardType(CardType* type, int infrared)
{
u8 sr = 0;
u32 jedec = 0;
u32 tries = 0;
u8 sr = 0;
u32 jedec = 0;
u32 tries = 0;
CardType t = (infrared == 1) ? FLASH_INFRARED_DUMMY : FLASH_STD_DUMMY;
Result res;
Result res;
u32 jedecOrderedList[] = {0x204012, 0x621600, 0x204013, 0x621100, 0x204014, 0x202017};
u32 maxTries = (infrared == -1) ? 2 : 1; // note: infrared = -1 fails 1/3 of the time
while (tries < maxTries)
{
while (tries < maxTries) {
res = SPIReadJEDECIDAndStatusReg(t, &jedec, &sr); // dummy
//fprintf(stderr, "JEDEC: 0x%016lX\n", jedec);
//fprintf(stderr, "SPIReadJEDECIDAndStatusReg: %016lX\n", res);
//fprintf(stderr, "CardType (While inside maxTries loop): %016lX\n", t);
if (res) return res;
if ((sr & 0xfd) == 0x00 && (jedec != 0x00ffffff)) { break; }
if ((sr & 0xfd) == 0xF0 && (jedec == 0x00ffffff)) { t = EEPROM_512B; break; }
if ((sr & 0xfd) == 0x00 && (jedec == 0x00ffffff)) { t = EEPROM_STD_DUMMY; break; }
// fprintf(stderr, "JEDEC: 0x%016lX\n", jedec);
// fprintf(stderr, "SPIReadJEDECIDAndStatusReg: %016lX\n", res);
// fprintf(stderr, "CardType (While inside maxTries loop): %016lX\n", t);
if (res)
return res;
if ((sr & 0xfd) == 0x00 && (jedec != 0x00ffffff)) {
break;
}
if ((sr & 0xfd) == 0xF0 && (jedec == 0x00ffffff)) {
t = EEPROM_512B;
break;
}
if ((sr & 0xfd) == 0x00 && (jedec == 0x00ffffff)) {
t = EEPROM_STD_DUMMY;
break;
}
++tries;
t = FLASH_INFRARED_DUMMY;
}
//fprintf(stderr, "CardType (after the maxTries loop): %016lX\n", t);
if (t == EEPROM_512B)
{
//fprintf(stderr, "Type is EEPROM_512B: %d\n", t);
// fprintf(stderr, "CardType (after the maxTries loop): %016lX\n", t);
if (t == EEPROM_512B) {
// fprintf(stderr, "Type is EEPROM_512B: %d\n", t);
*type = t;
return 0;
}
else if (t == EEPROM_STD_DUMMY)
{
else if (t == EEPROM_STD_DUMMY) {
bool mirrored = false;
if ((res = _SPIIsDataMirrored(t, 8192, &mirrored))) { return res; }
if (mirrored) t = EEPROM_8KB;
else
{
if ((res = _SPIIsDataMirrored(t, 65536, &mirrored))) { return res; }
if (mirrored) t = EEPROM_64KB;
else t = EEPROM_128KB;
if ((res = _SPIIsDataMirrored(t, 8192, &mirrored))) {
return res;
}
if (mirrored)
t = EEPROM_8KB;
else {
if ((res = _SPIIsDataMirrored(t, 65536, &mirrored))) {
return res;
}
if (mirrored)
t = EEPROM_64KB;
else
t = EEPROM_128KB;
}
*type = t;
//fprintf(stderr, "Type: %d\n", t);
// fprintf(stderr, "Type: %d\n", t);
return 0;
}
else if (t == FLASH_INFRARED_DUMMY)
{
if (infrared == 0) *type = NO_CHIP; // did anything go wrong?
if (jedec == jedecOrderedList[0] || jedec == jedecOrderedList[1]) *type = FLASH_256KB_INFRARED;
else *type = FLASH_512KB_INFRARED;
return 0;
}
else
{
if (infrared == 1)
{
else if (t == FLASH_INFRARED_DUMMY) {
if (infrared == 0)
*type = NO_CHIP; // did anything go wrong?
//fprintf(stderr, "infrared is 1, *type = NO_CHIP\n");
if (jedec == jedecOrderedList[0] || jedec == jedecOrderedList[1])
*type = FLASH_256KB_INFRARED;
else
*type = FLASH_512KB_INFRARED;
return 0;
}
else {
if (infrared == 1) {
*type = NO_CHIP; // did anything go wrong?
// fprintf(stderr, "infrared is 1, *type = NO_CHIP\n");
}
if (jedec == 0x204017) {
*type = FLASH_8MB;
return 0;
} // 8MB. savegame-manager: which one? (more work is required to unlock this save chip!)
if (jedec == 0x208013) {
*type = FLASH_512KB_1;
return 0;
}
if (jedec == 0x204017) { *type = FLASH_8MB; return 0; } // 8MB. savegame-manager: which one? (more work is required to unlock this save chip!)
if (jedec == 0x208013) { *type = FLASH_512KB_1; return 0; }
for (int i = 0; i < 6; ++i)
{
if(jedec == jedecOrderedList[i])
{
*type = (CardType)((int) FLASH_256KB_1 + i);
//fprintf(stderr, "Found a jedec equal to one in the ordered list. Type: %016lX", *type);
for (int i = 0; i < 6; ++i) {
if (jedec == jedecOrderedList[i]) {
*type = (CardType)((int)FLASH_256KB_1 + i);
// fprintf(stderr, "Found a jedec equal to one in the ordered list. Type: %016lX", *type);
return 0;
}
}
}
//fprintf(stderr, "*type = NO_CHIP\n");
// fprintf(stderr, "*type = NO_CHIP\n");
*type = NO_CHIP;
return 0;
}

View file

@ -1,48 +1,47 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "thread.hpp"
static std::vector<Thread> threads;
static bool forceRefresh = false;
static bool forceRefresh = false;
static volatile bool isLoadingTitles = false;
void Threads::create(ThreadFunc entrypoint)
{
s32 prio = 0;
svcGetThreadPriority(&prio, CUR_THREAD_HANDLE);
Thread thread = threadCreate((ThreadFunc)entrypoint, NULL, 64*1024, prio-1, -2, false);
Thread thread = threadCreate((ThreadFunc)entrypoint, NULL, 64 * 1024, prio - 1, -2, false);
threads.push_back(thread);
}
void Threads::destroy(void)
{
for (u32 i = 0; i < threads.size(); i++)
{
for (u32 i = 0; i < threads.size(); i++) {
threadJoin(threads.at(i), U64_MAX);
threadFree(threads.at(i));
}
@ -51,13 +50,12 @@ void Threads::destroy(void)
void Threads::titles(void)
{
// don't load titles while they're loading
if (isLoadingTitles)
{
if (isLoadingTitles) {
return;
}
isLoadingTitles = true;
loadTitles(forceRefresh);
forceRefresh = true;
forceRefresh = true;
isLoadingTitles = false;
}

File diff suppressed because it is too large Load diff

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "util.hpp"
@ -44,7 +44,8 @@ Result servicesInit(void)
Result res = 0;
Handle hbldrHandle;
if (R_FAILED(res = svcConnectToPort(&hbldrHandle, "hb:ldr"))) return res;
if (R_FAILED(res = svcConnectToPort(&hbldrHandle, "hb:ldr")))
return res;
romfsInit();
sdmcInit();
@ -52,16 +53,17 @@ Result servicesInit(void)
srvInit();
amInit();
pxiDevInit();
if (R_FAILED(res = Archive::init())) return res;
if (R_FAILED(res = Archive::init()))
return res;
mkdir("sdmc:/3ds", 777);
mkdir("sdmc:/3ds/Checkpoint", 777);
mkdir("sdmc:/3ds/Checkpoint/saves", 777);
mkdir("sdmc:/3ds/Checkpoint/extdata", 777);
mkdir("sdmc:/3ds/Checkpoint/cheats", 777);
mkdir("sdmc:/cheats", 777);
Gui::init();
Threads::create((ThreadFunc)CheatManager::init);
@ -77,16 +79,14 @@ void calculateTitleDBHash(u8* hash)
{
u32 titleCount, nandCount, titlesRead, nandTitlesRead;
AM_GetTitleCount(MEDIATYPE_SD, &titleCount);
if (Configuration::getInstance().nandSaves())
{
if (Configuration::getInstance().nandSaves()) {
AM_GetTitleCount(MEDIATYPE_NAND, &nandCount);
u64 buf[titleCount + nandCount];
AM_GetTitleList(&titlesRead, MEDIATYPE_SD, titleCount, buf);
AM_GetTitleList(&nandTitlesRead, MEDIATYPE_NAND, nandCount, buf + titlesRead * sizeof(u64));
sha256(hash, (u8*)buf, (titleCount + nandCount) * sizeof(u64));
}
else
{
else {
u64 buf[titleCount];
AM_GetTitleList(&titlesRead, MEDIATYPE_SD, titleCount, buf);
sha256(hash, (u8*)buf, titleCount * sizeof(u64));
@ -96,23 +96,22 @@ void calculateTitleDBHash(u8* hash)
std::u16string StringUtils::UTF8toUTF16(const char* src)
{
char16_t tmp[256] = {0};
utf8_to_utf16((uint16_t *)tmp, (uint8_t *)src, 256);
utf8_to_utf16((uint16_t*)tmp, (uint8_t*)src, 256);
return std::u16string(tmp);
}
std::u16string StringUtils::removeForbiddenCharacters(std::u16string src)
{
static const std::u16string illegalChars = StringUtils::UTF8toUTF16(".,!\\/:?*\"<>|");
for (size_t i = 0; i < src.length(); i++)
{
if (illegalChars.find(src[i]) != std::string::npos)
{
for (size_t i = 0; i < src.length(); i++) {
if (illegalChars.find(src[i]) != std::string::npos) {
src[i] = ' ';
}
}
size_t i;
for (i = src.length() - 1; i > 0 && src[i] == L' '; i--);
for (i = src.length() - 1; i > 0 && src[i] == L' '; i--)
;
src.erase(i + 1, src.length() - i);
return src;
@ -123,51 +122,42 @@ static std::queue<u16> widthCacheOrder;
std::string StringUtils::splitWord(const std::string& text, float scaleX, float maxWidth)
{
std::string word = text;
std::string word = text;
float currentWidth = 0.0f;
if (StringUtils::textWidth(word, scaleX) > maxWidth)
{
for (size_t i = 0; i < word.size(); i++)
{
if (StringUtils::textWidth(word, scaleX) > maxWidth) {
for (size_t i = 0; i < word.size(); i++) {
u16 codepoint = 0xFFFF;
int iMod = 0;
if (word[i] & 0x80 && word[i] & 0x40 && word[i] & 0x20 && !(word[i] & 0x10) && i + 2 < word.size())
{
int iMod = 0;
if (word[i] & 0x80 && word[i] & 0x40 && word[i] & 0x20 && !(word[i] & 0x10) && i + 2 < word.size()) {
codepoint = word[i] & 0x0F;
codepoint = codepoint << 6 | (word[i + 1] & 0x3F);
codepoint = codepoint << 6 | (word[i + 2] & 0x3F);
iMod = 2;
iMod = 2;
}
else if (word[i] & 0x80 && word[i] & 0x40 && !(word[i] & 0x20) && i + 1 < word.size())
{
else if (word[i] & 0x80 && word[i] & 0x40 && !(word[i] & 0x20) && i + 1 < word.size()) {
codepoint = word[i] & 0x1F;
codepoint = codepoint << 6 | (word[i + 1] & 0x3F);
iMod = 1;
iMod = 1;
}
else if (!(word[i] & 0x80))
{
else if (!(word[i] & 0x80)) {
codepoint = word[i];
}
float charWidth;
auto width = widthCache.find(codepoint);
if (width != widthCache.end())
{
if (width != widthCache.end()) {
charWidth = width->second->charWidth * scaleX;
}
else
{
else {
widthCache.insert_or_assign(codepoint, fontGetCharWidthInfo(fontGlyphIndexFromCodePoint(codepoint)));
widthCacheOrder.push(codepoint);
if (widthCache.size() > 512)
{
if (widthCache.size() > 512) {
widthCache.erase(widthCacheOrder.front());
widthCacheOrder.pop();
}
charWidth = widthCache[codepoint]->charWidth * scaleX;
}
currentWidth += charWidth;
if (currentWidth > maxWidth)
{
if (currentWidth > maxWidth) {
word.insert(i, 1, '\n');
currentWidth = charWidth;
}
@ -180,46 +170,38 @@ std::string StringUtils::splitWord(const std::string& text, float scaleX, float
float StringUtils::textWidth(const std::string& text, float scaleX)
{
float ret = 0.0f;
float ret = 0.0f;
float largestRet = 0.0f;
for (size_t i = 0; i < text.size(); i++)
{
if (text[i] == '\n')
{
for (size_t i = 0; i < text.size(); i++) {
if (text[i] == '\n') {
largestRet = std::max(largestRet, ret);
ret = 0.0f;
ret = 0.0f;
continue;
}
u16 codepoint = 0xFFFF;
if (text[i] & 0x80 && text[i] & 0x40 && text[i] & 0x20 && !(text[i] & 0x10) && i + 2 < text.size())
{
if (text[i] & 0x80 && text[i] & 0x40 && text[i] & 0x20 && !(text[i] & 0x10) && i + 2 < text.size()) {
codepoint = text[i] & 0x0F;
codepoint = codepoint << 6 | (text[i + 1] & 0x3F);
codepoint = codepoint << 6 | (text[i + 2] & 0x3F);
i += 2;
}
else if (text[i] & 0x80 && text[i] & 0x40 && !(text[i] & 0x20) && i + 1 < text.size())
{
else if (text[i] & 0x80 && text[i] & 0x40 && !(text[i] & 0x20) && i + 1 < text.size()) {
codepoint = text[i] & 0x1F;
codepoint = codepoint << 6 | (text[i + 1] & 0x3F);
i += 1;
}
else if (!(text[i] & 0x80))
{
else if (!(text[i] & 0x80)) {
codepoint = text[i];
}
float charWidth;
auto width = widthCache.find(codepoint);
if (width != widthCache.end())
{
if (width != widthCache.end()) {
charWidth = width->second->charWidth * scaleX;
}
else
{
else {
widthCache.insert_or_assign(codepoint, fontGetCharWidthInfo(fontGlyphIndexFromCodePoint(codepoint)));
widthCacheOrder.push(codepoint);
if (widthCache.size() > 1000)
{
if (widthCache.size() > 1000) {
widthCache.erase(widthCacheOrder.front());
widthCacheOrder.pop();
}
@ -232,43 +214,35 @@ float StringUtils::textWidth(const std::string& text, float scaleX)
float StringUtils::textWidth(const C2D_Text& text, float scaleX)
{
return ceilf(text.width*scaleX);
return ceilf(text.width * scaleX);
}
std::string StringUtils::wrap(const std::string& text, float scaleX, float maxWidth)
{
if (textWidth(text, scaleX) <= maxWidth)
{
if (textWidth(text, scaleX) <= maxWidth) {
return text;
}
std::string dst, line, word;
dst = line = word = "";
for (std::string::const_iterator it = text.begin(); it != text.end(); it++)
{
for (std::string::const_iterator it = text.begin(); it != text.end(); it++) {
word += *it;
if (*it == ' ')
{
if (*it == ' ') {
// split single words that are bigger than maxWidth
if (StringUtils::textWidth(line + word, scaleX) <= maxWidth)
{
if (StringUtils::textWidth(line + word, scaleX) <= maxWidth) {
line += word;
}
else
{
if (StringUtils::textWidth(word, scaleX) > maxWidth)
{
else {
if (StringUtils::textWidth(word, scaleX) > maxWidth) {
line += word;
line = StringUtils::splitWord(line, scaleX, maxWidth);
word = line.substr(line.find('\n')+1, std::string::npos);
word = line.substr(line.find('\n') + 1, std::string::npos);
line = line.substr(0, line.find('\n')); // Split line on first newLine; assign second part to word and first to line
}
if (line[line.size() - 1] == ' ')
{
if (line[line.size() - 1] == ' ') {
dst += line.substr(0, line.size() - 1) + '\n';
}
else
{
else {
dst += line + '\n';
}
line = word;
@ -280,25 +254,20 @@ std::string StringUtils::wrap(const std::string& text, float scaleX, float maxWi
// "Another iteration" of the loop b/c it probably won't end with a space
// If it does, no harm done
// word = StringUtils::splitWord(word, scaleX, maxWidth);
if (StringUtils::textWidth(line + word, scaleX) <= maxWidth)
{
if (StringUtils::textWidth(line + word, scaleX) <= maxWidth) {
dst += line + word;
}
else
{
if (StringUtils::textWidth(word, scaleX) > maxWidth)
{
else {
if (StringUtils::textWidth(word, scaleX) > maxWidth) {
line += word;
line = StringUtils::splitWord(line, scaleX, maxWidth);
word = line.substr(line.find('\n')+1, std::string::npos);
word = line.substr(line.find('\n') + 1, std::string::npos);
line = line.substr(0, line.find('\n'));
}
if (line[line.size() - 1] == ' ')
{
if (line[line.size() - 1] == ' ') {
dst += line.substr(0, line.size() - 1) + '\n' + word;
}
else
{
else {
dst += line + '\n' + word;
}
}

View file

@ -12,4 +12,7 @@ clean:
switch:
@$(MAKE) -C switch
.PHONY: $(SUBDIRS)
format:
@for dir in $(SUBDIRS); do $(MAKE) -C $$dir format; done
.PHONY: $(SUBDIRS) clean format

View file

@ -1,48 +1,49 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "common.hpp"
std::string DateTime::timeStr(void)
{
time_t unixTime = time(NULL);
time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t*)&unixTime);
return StringUtils::format("%02i:%02i:%02i", timeStruct->tm_hour, timeStruct->tm_min, timeStruct->tm_sec);
}
std::string DateTime::dateTimeStr(void)
{
time_t unixTime = time(NULL);
time_t unixTime = time(NULL);
struct tm* timeStruct = gmtime((const time_t*)&unixTime);
return StringUtils::format("%04i%02i%02i-%02i%02i%02i", timeStruct->tm_year + 1900, timeStruct->tm_mon + 1, timeStruct->tm_mday, timeStruct->tm_hour, timeStruct->tm_min, timeStruct->tm_sec);
return StringUtils::format("%04i%02i%02i-%02i%02i%02i", timeStruct->tm_year + 1900, timeStruct->tm_mon + 1, timeStruct->tm_mday,
timeStruct->tm_hour, timeStruct->tm_min, timeStruct->tm_sec);
}
std::string StringUtils::UTF16toUTF8(const std::u16string& src)
{
static std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
static std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t> convert;
std::string dst = convert.to_bytes(src);
return dst;
}
@ -50,16 +51,15 @@ std::string StringUtils::UTF16toUTF8(const std::u16string& src)
std::string StringUtils::removeForbiddenCharacters(std::string src)
{
static const std::string illegalChars = ".,!\\/:?*\"<>|";
for (size_t i = 0, sz = src.length(); i < sz; i++)
{
if (illegalChars.find(src[i]) != std::string::npos)
{
for (size_t i = 0, sz = src.length(); i < sz; i++) {
if (illegalChars.find(src[i]) != std::string::npos) {
src[i] = ' ';
}
}
size_t i;
for (i = src.length() - 1; i > 0 && src[i] == ' '; i--);
for (i = src.length() - 1; i > 0 && src[i] == ' '; i--)
;
src.erase(i + 1, src.length() - i);
return src;
@ -68,7 +68,7 @@ std::string StringUtils::removeForbiddenCharacters(std::string src)
std::string StringUtils::format(const std::string fmt_str, ...)
{
va_list ap;
char *fp = NULL;
char* fp = NULL;
va_start(ap, fmt_str);
vasprintf(&fp, fmt_str.c_str(), ap);
va_end(ap);
@ -78,10 +78,9 @@ std::string StringUtils::format(const std::string fmt_str, ...)
std::string StringUtils::sizeString(double size)
{
int i = 0;
int i = 0;
static const char* units[] = {"B", "kB", "MB", "GB"};
while (size > 1024)
{
while (size > 1024) {
size /= 1024;
i++;
}
@ -90,31 +89,25 @@ std::string StringUtils::sizeString(double size)
bool StringUtils::containsInvalidChar(const std::string& str)
{
for (size_t i = 0, sz = str.length(); i < sz; i++)
{
if (!isascii(str[i]))
{
for (size_t i = 0, sz = str.length(); i < sz; i++) {
if (!isascii(str[i])) {
return true;
}
}
return false;
}
void StringUtils::ltrim(std::string &s)
void StringUtils::ltrim(std::string& s)
{
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) {
return !std::isspace(ch);
}));
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) { return !std::isspace(ch); }));
}
void StringUtils::rtrim(std::string &s)
void StringUtils::rtrim(std::string& s)
{
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) {
return !std::isspace(ch);
}).base(), s.end());
s.erase(std::find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch); }).base(), s.end());
}
void StringUtils::trim(std::string &s)
void StringUtils::trim(std::string& s)
{
ltrim(s);
rtrim(s);
@ -124,5 +117,5 @@ char* getConsoleIP(void)
{
struct in_addr in;
in.s_addr = gethostid();
return inet_ntoa(in);
return inet_ntoa(in);
}

View file

@ -1,63 +1,61 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef COMMON_HPP
#define COMMON_HPP
#include <algorithm>
#include <arpa/inet.h>
#include <codecvt>
#include <cstdio>
#include <locale>
#include <memory>
#include <stdarg.h>
#include <string>
#include <string.h>
#include <time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdarg.h>
#include <string.h>
#include <string>
#include <sys/socket.h>
#include <time.h>
#include <unistd.h>
namespace DateTime
{
namespace DateTime {
std::string timeStr(void);
std::string dateTimeStr(void);
}
namespace StringUtils
{
bool containsInvalidChar(const std::string& str);
std::string escapeJson(const std::string &s);
namespace StringUtils {
bool containsInvalidChar(const std::string& str);
std::string escapeJson(const std::string& s);
std::string format(const std::string fmt_str, ...);
std::string removeForbiddenCharacters(std::string src);
std::string sizeString(double size);
std::string UTF16toUTF8(const std::u16string& src);
void ltrim(std::string &s);
void rtrim(std::string &s);
void trim(std::string &s);
void ltrim(std::string& s);
void rtrim(std::string& s);
void trim(std::string& s);
}
char* getConsoleIP(void);

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef ICLICKABLE_HPP
#define ICLICKABLE_HPP
@ -33,68 +33,52 @@ typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
template<typename T>
class IClickable
{
template <typename T>
class IClickable {
public:
IClickable(int x, int y, u16 w, u16 h, T colorBg, T colorText, const std::string& message, bool centered)
: mx(x), my(y), mw(w), mh(h), mColorBg(colorBg), mColorText(colorText), mText(message), mCentered(centered)
: mx(x), my(y), mw(w), mh(h), mColorBg(colorBg), mColorText(colorText), mText(message), mCentered(centered)
{
mOldPressed = false;
mSelected = false;
mOldPressed = false;
mSelected = false;
mCanChangeColorWhenSelected = false;
}
virtual ~IClickable(void) { }
virtual ~IClickable(void) {}
virtual void draw(float size, T overlay) = 0;
virtual void drawOutline(T color) = 0;
virtual bool held(void) = 0;
virtual bool released(void) = 0;
virtual void drawOutline(T color) = 0;
virtual bool held(void) = 0;
virtual bool released(void) = 0;
void setColors(T bg, T text)
{
mColorBg = bg;
mColorBg = bg;
mColorText = text;
}
std::string text(void)
{
return mText;
}
std::string text(void) { return mText; }
void text(const std::string& v)
{
mText = v;
}
void text(const std::string& v) { mText = v; }
bool selected(void)
{
return mSelected;
}
bool selected(void) { return mSelected; }
void selected(bool selected)
{
mSelected = selected;
}
void selected(bool selected) { mSelected = selected; }
void canChangeColorWhenSelected(bool c)
{
mCanChangeColorWhenSelected = c;
}
void canChangeColorWhenSelected(bool c) { mCanChangeColorWhenSelected = c; }
protected:
int mx;
int my;
u16 mw;
u16 mh;
T mColorBg;
T mColorText;
protected:
int mx;
int my;
u16 mw;
u16 mh;
T mColorBg;
T mColorText;
std::string mText;
bool mCanChangeColorWhenSelected;
bool mCentered;
bool mOldPressed;
bool mSelected;
bool mCanChangeColorWhenSelected;
bool mCentered;
bool mOldPressed;
bool mSelected;
};
#endif

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "ihid.hpp"
@ -54,7 +54,7 @@ void IHid::page(int v)
void IHid::reset(void)
{
mIndex = 0;
mPage = 0;
mPage = 0;
}
size_t IHid::maxVisibleEntries(void)
@ -64,29 +64,25 @@ size_t IHid::maxVisibleEntries(void)
size_t IHid::maxEntries(size_t count)
{
return (count - mPage*mMaxVisibleEntries) > mMaxVisibleEntries ? mMaxVisibleEntries - 1 : count - mPage*mMaxVisibleEntries - 1;
return (count - mPage * mMaxVisibleEntries) > mMaxVisibleEntries ? mMaxVisibleEntries - 1 : count - mPage * mMaxVisibleEntries - 1;
}
void IHid::page_back(void)
{
if (mPage > 0)
{
if (mPage > 0) {
mPage--;
}
else if (mPage == 0)
{
else if (mPage == 0) {
mPage = mMaxPages - 1;
}
}
void IHid::page_forward(void)
{
if (mPage < (int)mMaxPages - 1)
{
if (mPage < (int)mMaxPages - 1) {
mPage++;
}
else if (mPage == (int)mMaxPages - 1)
{
else if (mPage == (int)mMaxPages - 1) {
mPage = 0;
}
}

View file

@ -1,105 +1,99 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef IHID_HPP
#define IHID_HPP
#include <cstdint>
#include <cmath>
#include "common.hpp"
#include <cmath>
#include <cstdint>
typedef uint64_t u64;
class IHid
{
class IHid {
public:
IHid(size_t entries, size_t columns)
: mMaxVisibleEntries(entries), mColumns(columns)
IHid(size_t entries, size_t columns) : mMaxVisibleEntries(entries), mColumns(columns)
{
reset();
mMaxPages = 0;
mMaxPages = 0;
mCurrentTime = 0;
mLastTime = 0;
mDelayTicks = 1e10;
mLastTime = 0;
mDelayTicks = 1e10;
}
virtual ~IHid(void) { }
virtual ~IHid(void) {}
size_t fullIndex(void);
size_t index(void);
void index(size_t v);
void index(size_t v);
size_t maxEntries(size_t max);
size_t maxVisibleEntries(void);
int page(void);
void page(int v);
void reset(void);
int page(void);
void page(int v);
void reset(void);
protected:
void page_back(void);
void page_forward(void);
virtual void update(size_t count) = 0;
virtual u64 down(void) = 0;
virtual u64 held(void) = 0;
virtual u64 tick(void) = 0;
virtual u64 _KEY_ZL(void) = 0;
virtual u64 _KEY_ZR(void) = 0;
virtual u64 _KEY_LEFT(void) = 0;
virtual u64 down(void) = 0;
virtual u64 held(void) = 0;
virtual u64 tick(void) = 0;
virtual u64 _KEY_ZL(void) = 0;
virtual u64 _KEY_ZR(void) = 0;
virtual u64 _KEY_LEFT(void) = 0;
virtual u64 _KEY_RIGHT(void) = 0;
virtual u64 _KEY_UP(void) = 0;
virtual u64 _KEY_DOWN(void) = 0;
virtual u64 _KEY_UP(void) = 0;
virtual u64 _KEY_DOWN(void) = 0;
size_t mIndex;
int mPage;
int mPage;
size_t mMaxPages;
size_t mMaxVisibleEntries;
size_t mColumns;
u64 mCurrentTime;
u64 mLastTime;
u64 mDelayTicks;
u64 mCurrentTime;
u64 mLastTime;
u64 mDelayTicks;
};
class IHidVertical : public IHid
{
class IHidVertical : public IHid {
public:
IHidVertical(size_t entries, size_t columns)
: IHid(entries, columns) { }
IHidVertical(size_t entries, size_t columns) : IHid(entries, columns) {}
virtual ~IHidVertical(void) { }
virtual ~IHidVertical(void) {}
void update(size_t count) override;
};
class IHidHorizontal : public IHid
{
class IHidHorizontal : public IHid {
public:
IHidHorizontal(size_t entries, size_t columns)
: IHid(entries, columns) { }
IHidHorizontal(size_t entries, size_t columns) : IHid(entries, columns) {}
virtual ~IHidHorizontal(void) { }
virtual ~IHidHorizontal(void) {}
void update(size_t count) override;
};

View file

@ -1,244 +1,191 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "ihid.hpp"
void IHidHorizontal::update(size_t count)
{
mCurrentTime = tick();
size_t rows = mMaxVisibleEntries / mColumns;
mMaxPages = (count % mMaxVisibleEntries == 0) ? count / mMaxVisibleEntries : count / mMaxVisibleEntries + 1;
u64 kHeld = held();
u64 kDown = down();
if (kDown & _KEY_ZL())
{
size_t rows = mMaxVisibleEntries / mColumns;
mMaxPages = (count % mMaxVisibleEntries == 0) ? count / mMaxVisibleEntries : count / mMaxVisibleEntries + 1;
u64 kHeld = held();
u64 kDown = down();
if (kDown & _KEY_ZL()) {
page_back();
if (mIndex > maxEntries(count))
{
if (mIndex > maxEntries(count)) {
mIndex = maxEntries(count);
}
}
else if (kDown & _KEY_ZR())
{
else if (kDown & _KEY_ZR()) {
page_forward();
if (mIndex > maxEntries(count))
{
if (mIndex > maxEntries(count)) {
mIndex = maxEntries(count);
}
}
else if (mColumns > 1)
{
if (kDown & _KEY_LEFT())
{
if (mIndex % mColumns != 0)
{
else if (mColumns > 1) {
if (kDown & _KEY_LEFT()) {
if (mIndex % mColumns != 0) {
mIndex--;
}
else
{
else {
page_back();
mIndex += mColumns - 1;
}
}
else if (kDown & _KEY_RIGHT())
{
if (mIndex % mColumns != mColumns - 1)
{
if (mIndex + mPage * mMaxVisibleEntries == count - 1)
{
else if (kDown & _KEY_RIGHT()) {
if (mIndex % mColumns != mColumns - 1) {
if (mIndex + mPage * mMaxVisibleEntries == count - 1) {
page_forward();
mIndex = (mIndex / mColumns) * mColumns;
}
else
{
else {
mIndex++;
}
}
else
{
else {
page_forward();
mIndex -= mColumns - 1;
}
}
else if (kDown & _KEY_UP())
{
if (mIndex < mColumns)
{
else if (kDown & _KEY_UP()) {
if (mIndex < mColumns) {
mIndex += mColumns * (rows - 1);
}
else
{
else {
mIndex -= mColumns;
}
}
else if (kDown & _KEY_DOWN())
{
if (mIndex >= mColumns * (rows - 1))
{
else if (kDown & _KEY_DOWN()) {
if (mIndex >= mColumns * (rows - 1)) {
mIndex -= mColumns * (rows - 1);
}
else
{
else {
mIndex += mColumns;
}
}
else if (kHeld & _KEY_LEFT())
{
if (mCurrentTime <= mLastTime + mDelayTicks)
{
else if (kHeld & _KEY_LEFT()) {
if (mCurrentTime <= mLastTime + mDelayTicks) {
return;
}
if (mIndex % mColumns != 0)
{
if (mIndex % mColumns != 0) {
mIndex--;
}
else
{
else {
page_back();
mIndex += mColumns - 1;
}
}
else if (kHeld & _KEY_RIGHT())
{
if (mCurrentTime <= mLastTime + mDelayTicks)
{
else if (kHeld & _KEY_RIGHT()) {
if (mCurrentTime <= mLastTime + mDelayTicks) {
return;
}
if (mIndex % mColumns != mColumns - 1)
{
if (mIndex + mPage * mMaxVisibleEntries == count - 1)
{
if (mIndex % mColumns != mColumns - 1) {
if (mIndex + mPage * mMaxVisibleEntries == count - 1) {
page_forward();
mIndex = (mIndex / mColumns) * mColumns;
}
else
{
else {
mIndex++;
}
}
else
{
else {
page_forward();
mIndex -= mColumns - 1;
}
}
else if (kHeld & _KEY_UP())
{
if (mCurrentTime <= mLastTime + mDelayTicks)
{
else if (kHeld & _KEY_UP()) {
if (mCurrentTime <= mLastTime + mDelayTicks) {
return;
}
if (mIndex < mColumns)
{
if (mIndex < mColumns) {
mIndex += mColumns * (rows - 1);
}
else
{
else {
mIndex -= mColumns;
}
}
else if (kHeld & _KEY_DOWN())
{
if (mCurrentTime <= mLastTime + mDelayTicks)
{
else if (kHeld & _KEY_DOWN()) {
if (mCurrentTime <= mLastTime + mDelayTicks) {
return;
}
if (mIndex >= mColumns * (rows - 1))
{
if (mIndex >= mColumns * (rows - 1)) {
mIndex -= mColumns * (rows - 1);
}
else
{
else {
mIndex += mColumns;
}
}
}
else
{
if (kDown & _KEY_UP())
{
if (mIndex > 0)
{
else {
if (kDown & _KEY_UP()) {
if (mIndex > 0) {
mIndex--;
}
else if (mIndex == 0)
{
else if (mIndex == 0) {
page_back();
mIndex = maxEntries(count);
}
}
else if (kDown & _KEY_DOWN())
{
if (mIndex < maxEntries(count))
{
else if (kDown & _KEY_DOWN()) {
if (mIndex < maxEntries(count)) {
mIndex++;
}
else if (mIndex == maxEntries(count))
{
else if (mIndex == maxEntries(count)) {
page_forward();
mIndex = 0;
}
}
else if (kHeld & _KEY_UP())
{
if (mCurrentTime <= mLastTime + mDelayTicks)
{
else if (kHeld & _KEY_UP()) {
if (mCurrentTime <= mLastTime + mDelayTicks) {
return;
}
if (mIndex > 0)
{
if (mIndex > 0) {
mIndex--;
}
else if (mIndex == 0)
{
else if (mIndex == 0) {
page_back();
mIndex = maxEntries(count);
}
}
else if (kHeld & _KEY_DOWN())
{
if (mCurrentTime <= mLastTime + mDelayTicks)
{
else if (kHeld & _KEY_DOWN()) {
if (mCurrentTime <= mLastTime + mDelayTicks) {
return;
}
if (mIndex < maxEntries(count))
{
if (mIndex < maxEntries(count)) {
mIndex++;
}
else if (mIndex == maxEntries(count))
{
else if (mIndex == maxEntries(count)) {
page_forward();
mIndex = 0;
}
}
}
if (mIndex > maxEntries(count))
{
if (mIndex > maxEntries(count)) {
mIndex = maxEntries(count);
}
mLastTime = mCurrentTime;

View file

@ -1,243 +1,189 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "ihid.hpp"
void IHidVertical::update(size_t count)
{
mCurrentTime = tick();
size_t rows = mMaxVisibleEntries / mColumns;
mMaxPages = (count % mMaxVisibleEntries == 0) ? count / mMaxVisibleEntries : count / mMaxVisibleEntries + 1;
u64 kHeld = held();
u64 kDown = down();
if (kDown & _KEY_ZL())
{
size_t rows = mMaxVisibleEntries / mColumns;
mMaxPages = (count % mMaxVisibleEntries == 0) ? count / mMaxVisibleEntries : count / mMaxVisibleEntries + 1;
u64 kHeld = held();
u64 kDown = down();
if (kDown & _KEY_ZL()) {
page_back();
}
else if (kDown & _KEY_ZR())
{
else if (kDown & _KEY_ZR()) {
page_forward();
}
else if (mColumns > 1)
{
if (kDown & _KEY_LEFT())
{
if (mIndex % rows != mIndex)
{
else if (mColumns > 1) {
if (kDown & _KEY_LEFT()) {
if (mIndex % rows != mIndex) {
mIndex -= rows;
}
else
{
else {
page_back();
mIndex += rows;
}
}
else if (kDown & _KEY_RIGHT())
{
if (maxEntries(count) < rows)
{
else if (kDown & _KEY_RIGHT()) {
if (maxEntries(count) < rows) {
page_forward();
}
else if (mIndex + rows < mMaxVisibleEntries)
{
else if (mIndex + rows < mMaxVisibleEntries) {
mIndex += rows;
}
else
{
else {
page_forward();
mIndex -= rows;
}
}
else if (kDown & _KEY_UP())
{
if (mIndex % rows > 0)
{
else if (kDown & _KEY_UP()) {
if (mIndex % rows > 0) {
mIndex -= 1;
}
else
{
else {
mIndex = mIndex == rows ? mMaxVisibleEntries - 1 : ((mMaxVisibleEntries - 1) % rows);
}
}
else if (kDown & _KEY_DOWN())
{
if ((mIndex % rows) < rows - 1)
{
if (mIndex + mPage * mMaxVisibleEntries == count - 1)
{
else if (kDown & _KEY_DOWN()) {
if ((mIndex % rows) < rows - 1) {
if (mIndex + mPage * mMaxVisibleEntries == count - 1) {
mIndex = (mIndex / rows) * rows;
}
else
{
else {
mIndex += 1;
}
}
else
{
else {
mIndex = mIndex == rows - 1 ? 0 : rows;
}
}
else if (kHeld & _KEY_LEFT())
{
if (mCurrentTime <= mLastTime + mDelayTicks)
{
else if (kHeld & _KEY_LEFT()) {
if (mCurrentTime <= mLastTime + mDelayTicks) {
return;
}
if (mIndex % rows != mIndex)
{
if (mIndex % rows != mIndex) {
mIndex -= rows;
}
else
{
else {
page_back();
mIndex += rows;
}
}
else if (kHeld & _KEY_RIGHT())
{
if (mCurrentTime <= mLastTime + mDelayTicks)
{
else if (kHeld & _KEY_RIGHT()) {
if (mCurrentTime <= mLastTime + mDelayTicks) {
return;
}
if (maxEntries(count) < rows)
{
if (maxEntries(count) < rows) {
page_forward();
}
else if (mIndex + rows < mMaxVisibleEntries)
{
else if (mIndex + rows < mMaxVisibleEntries) {
mIndex += rows;
}
else
{
else {
page_forward();
mIndex -= rows;
}
}
else if (kHeld & _KEY_UP())
{
if (mCurrentTime <= mLastTime + mDelayTicks)
{
else if (kHeld & _KEY_UP()) {
if (mCurrentTime <= mLastTime + mDelayTicks) {
return;
}
if (mIndex % rows > 0)
{
if (mIndex % rows > 0) {
mIndex -= 1;
}
else
{
else {
mIndex = mIndex == rows ? mMaxVisibleEntries - 1 : ((mMaxVisibleEntries - 1) % rows);
}
}
else if (kHeld & _KEY_DOWN())
{
if (mCurrentTime <= mLastTime + mDelayTicks)
{
else if (kHeld & _KEY_DOWN()) {
if (mCurrentTime <= mLastTime + mDelayTicks) {
return;
}
if ((mIndex % rows) < rows - 1)
{
if (mIndex + mPage * mMaxVisibleEntries == count - 1)
{
if ((mIndex % rows) < rows - 1) {
if (mIndex + mPage * mMaxVisibleEntries == count - 1) {
mIndex = (mIndex / rows) * rows;
}
else
{
else {
mIndex += 1;
}
}
else
{
else {
mIndex = mIndex == rows - 1 ? 0 : rows;
}
}
}
else
{
if (kDown & _KEY_UP())
{
if (mIndex > 0)
{
else {
if (kDown & _KEY_UP()) {
if (mIndex > 0) {
mIndex--;
}
else if (mIndex == 0)
{
else if (mIndex == 0) {
page_back();
mIndex = maxEntries(count);
}
}
else if (kDown & _KEY_DOWN())
{
if (mIndex < maxEntries(count))
{
else if (kDown & _KEY_DOWN()) {
if (mIndex < maxEntries(count)) {
mIndex++;
}
else if (mIndex == maxEntries(count))
{
else if (mIndex == maxEntries(count)) {
page_forward();
mIndex = 0;
}
}
else if (kHeld & _KEY_UP())
{
if (mCurrentTime <= mLastTime + mDelayTicks)
{
else if (kHeld & _KEY_UP()) {
if (mCurrentTime <= mLastTime + mDelayTicks) {
return;
}
if (mIndex > 0)
{
if (mIndex > 0) {
mIndex--;
}
else if (mIndex == 0)
{
else if (mIndex == 0) {
page_back();
mIndex = maxEntries(count);
}
}
else if (kHeld & _KEY_DOWN())
{
if (mCurrentTime <= mLastTime + mDelayTicks)
{
else if (kHeld & _KEY_DOWN()) {
if (mCurrentTime <= mLastTime + mDelayTicks) {
return;
}
if (mIndex < maxEntries(count))
{
if (mIndex < maxEntries(count)) {
mIndex++;
}
else if (mIndex == maxEntries(count))
{
else if (mIndex == maxEntries(count)) {
page_forward();
mIndex = 0;
}
}
}
if (mIndex > maxEntries(count))
{
if (mIndex > maxEntries(count)) {
mIndex = maxEntries(count);
}
mLastTime = mCurrentTime;

View file

@ -1,125 +1,98 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef ISCROLLABLE_HPP
#define ISCROLLABLE_HPP
#include "iclickable.hpp"
#include <vector>
template<typename T>
class IScrollable
{
template <typename T>
class IScrollable {
public:
IScrollable(int x, int y, u16 w, u16 h, size_t visibleEntries)
: mx(x), my(y), mw(w), mh(h), mVisibleEntries(visibleEntries)
IScrollable(int x, int y, u16 w, u16 h, size_t visibleEntries) : mx(x), my(y), mw(w), mh(h), mVisibleEntries(visibleEntries)
{
mIndex = 0;
mPage = 0;
mPage = 0;
}
virtual ~IScrollable(void)
{
flush();
}
virtual ~IScrollable(void) { flush(); }
virtual void draw(bool condition = false) = 0;
virtual void draw(bool condition = false) = 0;
virtual void push_back(T color, T colorMessage, const std::string& message, bool selected) = 0;
virtual void updateSelection(void) = 0;
virtual void updateSelection(void) = 0;
std::string cellName(size_t index)
{
return mCells.at(index)->text();
}
std::string cellName(size_t index) { return mCells.at(index)->text(); }
void cellName(size_t index, const std::string& name)
{
mCells.at(index)->text(name);
}
void cellName(size_t index, const std::string& name) { mCells.at(index)->text(name); }
void flush(void)
{
for (size_t i = 0; i < size(); i++)
{
for (size_t i = 0; i < size(); i++) {
delete mCells[i];
}
mCells.clear();
}
size_t size(void)
{
return mCells.size();
}
size_t size(void) { return mCells.size(); }
size_t maxVisibleEntries(void)
{
return (size() - mPage*mVisibleEntries) > mVisibleEntries ? mVisibleEntries : size() - mPage*mVisibleEntries;
return (size() - mPage * mVisibleEntries) > mVisibleEntries ? mVisibleEntries : size() - mPage * mVisibleEntries;
}
size_t index(void)
{
return mIndex + mPage*mVisibleEntries;
}
size_t index(void) { return mIndex + mPage * mVisibleEntries; }
int page(void)
{
return mPage;
}
int page(void) { return mPage; }
virtual void resetIndex(void)
{
mIndex = 0;
mPage = 0;
mPage = 0;
}
void index(size_t i)
{
mPage = i / mVisibleEntries;
mPage = i / mVisibleEntries;
mIndex = i - mPage * mVisibleEntries;
}
size_t visibleEntries(void)
{
return mVisibleEntries;
}
size_t visibleEntries(void) { return mVisibleEntries; }
void selectRow(size_t i, bool selected)
{
mCells.at(i)->selected(selected);
}
void selectRow(size_t i, bool selected) { mCells.at(i)->selected(selected); }
protected:
int mx;
int my;
u16 mw;
u16 mh;
int mx;
int my;
u16 mw;
u16 mh;
size_t mVisibleEntries;
size_t mIndex;
int mPage;
std::vector
<IClickable<T>*> mCells;
int mPage;
std::vector<IClickable<T>*> mCells;
};
#endif

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "multiselection.hpp"
@ -46,20 +46,16 @@ void MS::clearSelectedEntries(void)
void MS::addSelectedEntry(size_t idx)
{
int existing = -1;
for (size_t i = 0, sz = selEnt.size(); i < sz && existing == -1; i++)
{
if (selEnt.at(i) == idx)
{
for (size_t i = 0, sz = selEnt.size(); i < sz && existing == -1; i++) {
if (selEnt.at(i) == idx) {
existing = (int)i;
}
}
if (existing == -1)
{
if (existing == -1) {
selEnt.push_back(idx);
}
else
{
else {
selEnt.erase(selEnt.begin() + existing);
}
}

View file

@ -1,33 +1,32 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include <vector>
namespace MS
{
namespace MS {
std::vector<size_t> selectedEntries(void);
bool multipleSelectionEnabled(void);
void clearSelectedEntries(void);

View file

@ -38,16 +38,18 @@ APP_TITLE := Checkpoint
APP_AUTHOR := Bernardo Giordano, FlagBrew
APP_VERSION := ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_MICRO}
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
OUTDIR := out
BUILD := build
SOURCES := source ../common ../3rd-party/mongoose
DATA := data
INCLUDES := include ../common ../3rd-party/mongoose ../3rd-party/json
EXEFS_SRC := exefs_src
ROMFS := romfs
SHARKIVE := ../sharkive
CHEATS := cheats
TARGET := $(subst $e ,_,$(notdir $(APP_TITLE)))
OUTDIR := out
BUILD := build
FORMATSOURCES := source ../common
SOURCES := $(FORMATSOURCES) ../3rd-party/mongoose
DATA := data
FORMATINCLUDES := include ../common
INCLUDES := $(FORMATINCLUDES) ../3rd-party/mongoose ../3rd-party/json
EXEFS_SRC := exefs_src
ROMFS := romfs
SHARKIVE := ../sharkive
CHEATS := cheats
#---------------------------------------------------------------------------------
# options for code generation
@ -160,7 +162,7 @@ ifneq ($(ROMFS),)
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
endif
.PHONY: $(BUILD) clean all
.PHONY: $(BUILD) clean all format
#---------------------------------------------------------------------------------
all: $(BUILD)
@ -179,9 +181,12 @@ endif
clean:
@echo clean ...
@rm -fr $(BUILD) $(OUTDIR)
#---------------------------------------------------------------------------------
format:
clang-format -i -style=file $(foreach dir,$(FORMATSOURCES),$(wildcard $(dir)/*.c) $(wildcard $(dir)/*.cpp)) $(foreach dir,$(FORMATINCLUDES),$(wildcard $(dir)/*.h) $(wildcard $(dir)/*.hpp))
#---------------------------------------------------------------------------------
else
.PHONY: all
DEPENDS := $(OFILES:.o=.d)

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef KEYBOARDMANAGER_HPP
#define KEYBOARDMANAGER_HPP
@ -31,8 +31,7 @@
#include <switch.h>
#include <utility>
class KeyboardManager
{
class KeyboardManager {
public:
static KeyboardManager& get(void)
{
@ -44,17 +43,14 @@ public:
void operator=(KeyboardManager const&) = delete;
std::pair<bool, std::string> keyboard(const std::string& suggestion);
std::pair<bool, Result> isSystemKeyboardAvailable(void)
{
return std::make_pair(systemKeyboardAvailable, res);
}
std::pair<bool, Result> isSystemKeyboardAvailable(void) { return std::make_pair(systemKeyboardAvailable, res); }
static const size_t CUSTOM_PATH_LEN = 49;
private:
KeyboardManager(void);
virtual ~KeyboardManager(void) { };
virtual ~KeyboardManager(void){};
Result res;
bool systemKeyboardAvailable;

View file

@ -1,21 +1,21 @@
#ifndef SDLHELPER_HPP
#define SDLHELPER_HPP
#include <switch.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <string>
#include <unordered_map>
#include "SDL_FontCache.h"
#include "colors.hpp"
#include "status.hpp"
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <string>
#include <switch.h>
#include <unordered_map>
bool SDLH_Init(void);
void SDLH_Exit(void);
void SDLH_ClearScreen(SDL_Color color);
void SDLH_DrawRect(int x, int y, int w, int h, SDL_Color color);
void SDLH_DrawText(int size, int x, int y, SDL_Color color, const char *text);
void SDLH_DrawText(int size, int x, int y, SDL_Color color, const char* text);
void SDLH_LoadImage(SDL_Texture** texture, char* path);
void SDLH_LoadImage(SDL_Texture** texture, u8* buff, size_t size);
void SDLH_DrawImage(SDL_Texture* texture, int x, int y);

View file

@ -42,7 +42,7 @@ extern "C" {
#endif
// Let's pretend this exists...
#define TTF_STYLE_OUTLINE 16
#define TTF_STYLE_OUTLINE 16
#define FC_Rect SDL_Rect
#define FC_Target SDL_Renderer
@ -51,28 +51,17 @@ extern "C" {
// SDL_FontCache types
typedef enum
{
FC_ALIGN_LEFT,
FC_ALIGN_CENTER,
FC_ALIGN_RIGHT
} FC_AlignEnum;
typedef enum { FC_ALIGN_LEFT, FC_ALIGN_CENTER, FC_ALIGN_RIGHT } FC_AlignEnum;
typedef enum
{
FC_FILTER_NEAREST,
FC_FILTER_LINEAR
} FC_FilterEnum;
typedef enum { FC_FILTER_NEAREST, FC_FILTER_LINEAR } FC_FilterEnum;
typedef struct FC_Scale
{
typedef struct FC_Scale {
float x;
float y;
} FC_Scale;
typedef struct FC_Effect
{
typedef struct FC_Effect {
FC_AlignEnum alignment;
FC_Scale scale;
SDL_Color color;
@ -82,8 +71,7 @@ typedef struct FC_Effect
// Opaque type
typedef struct FC_Font FC_Font;
typedef struct FC_GlyphData
{
typedef struct FC_GlyphData {
SDL_Rect rect;
int cache_level;
@ -107,7 +95,8 @@ FC_Font* FC_CreateFont(void);
Uint8 FC_LoadFontFromTTF(FC_Font* font, SDL_Renderer* renderer, TTF_Font* ttf, TTF_Font* ext, SDL_Color color);
Uint8 FC_LoadFont_RW(FC_Font* font, SDL_Renderer* renderer, SDL_RWops* file_rwops_ttf, SDL_RWops* file_rwops_ext, Uint8 own_rwops, Uint32 pointSize, SDL_Color color, int style);
Uint8 FC_LoadFont_RW(FC_Font* font, SDL_Renderer* renderer, SDL_RWops* file_rwops_ttf, SDL_RWops* file_rwops_ext, Uint8 own_rwops, Uint32 pointSize,
SDL_Color color, int style);
void FC_ClearFont(FC_Font* font);
@ -117,7 +106,6 @@ void FC_FreeFont(FC_Font* font);
char* FC_GetStringASCII(void);
// UTF-8 to SDL_FontCache codepoint conversion
/*!
@ -134,10 +122,10 @@ Parses the given codepoint and stores the UTF-8 bytes in 'result'. The result i
*/
void FC_GetUTF8FromCodepoint(char* result, Uint32 codepoint);
// UTF-8 string operations
/*! Allocates a new string of 'size' bytes that is already NULL-terminated. The NULL byte counts toward the size limit, as usual. Returns NULL if size is 0. */
/*! Allocates a new string of 'size' bytes that is already NULL-terminated. The NULL byte counts toward the size limit, as usual. Returns NULL if
* size is 0. */
char* U8_alloc(unsigned int size);
/*! Deallocates the given string. */
@ -164,10 +152,10 @@ int U8_strinsert(char* string, int position, const char* source, int max_bytes);
/*! Erases the UTF-8 character at the given position, moving the subsequent characters down. */
void U8_strdel(char* string, int position);
// Internal settings
/*! Sets the string from which to load the initial glyphs. Use this if you need upfront loading for any reason (such as lack of render-target support). */
/*! Sets the string from which to load the initial glyphs. Use this if you need upfront loading for any reason (such as lack of render-target
* support). */
void FC_SetLoadingString(FC_Font* font, const char* string);
/*! Returns the size of the internal buffer which is used for unpacking variadic text data. This buffer is shared by all FC_Fonts. */
@ -180,7 +168,6 @@ void FC_SetRenderCallback(FC_Rect (*callback)(FC_Image* src, FC_Rect* srcrect, F
FC_Rect FC_DefaultRenderCallback(FC_Image* src, FC_Rect* srcrect, FC_Target* dest, float x, float y, float xscale, float yscale);
// Custom caching
/*! Returns the number of cache levels that are active. */
@ -196,7 +183,6 @@ Uint8 FC_SetGlyphCacheLevel(FC_Font* font, int cache_level, FC_Image* cache_text
/*! Copies the given surface to the given cache level as a texture. New cache levels must be sequential. */
Uint8 FC_UploadGlyphCache(FC_Font* font, int cache_level, SDL_Surface* data_surface);
/*! Returns the number of codepoints that are stored in the font's glyph data map. */
unsigned int FC_GetNumCodepoints(FC_Font* font);
@ -209,7 +195,6 @@ Uint8 FC_GetGlyphData(FC_Font* font, FC_GlyphData* result, Uint32 codepoint);
/*! Sets the glyph data for the given codepoint. Duplicates are not checked. Returns a pointer to the stored data. */
FC_GlyphData* FC_SetGlyphData(FC_Font* font, Uint32 codepoint, FC_GlyphData glyph_data);
// Rendering
FC_Rect FC_Draw(FC_Font* font, FC_Target* dest, float x, float y, const char* formatted_text, ...);
@ -260,7 +245,6 @@ void FC_SetSpacing(FC_Font* font, int LetterSpacing);
void FC_SetLineSpacing(FC_Font* font, int LineSpacing);
void FC_SetDefaultColor(FC_Font* font, SDL_Color color);
#ifdef __cplusplus
}
#endif

View file

@ -1,58 +1,56 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef ACCOUNT_HPP
#define ACCOUNT_HPP
#include <string>
#include <string.h>
#include <switch.h>
#include <map>
#include <vector>
#include "SDLHelper.hpp"
#include "types.hpp"
#include <map>
#include <string.h>
#include <string>
#include <switch.h>
#include <vector>
#define USER_ICON_SIZE 64
struct User {
u128 id;
std::string name;
SDL_Texture* icon;
u128 id;
std::string name;
SDL_Texture* icon;
};
namespace Account
{
Result init(void);
void exit(void);
namespace Account {
Result init(void);
void exit(void);
std::vector
<u128> ids(void);
std::vector<u128> ids(void);
SDL_Texture* icon(u128 id);
u128 selectAccount(void);
std::string username(u128 id);
u128 selectAccount(void);
std::string username(u128 id);
}
#endif

View file

@ -1,44 +1,43 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef CHEATMANAGER_HPP
#define CHEATMANAGER_HPP
#include <switch.h>
#include <sys/stat.h>
#include <stdio.h>
#include <bzlib.h>
#include <errno.h>
#include "json.hpp"
#include "gui.hpp"
#include "json.hpp"
#include "main.hpp"
#include "scrollable.hpp"
#include <bzlib.h>
#include <errno.h>
#include <stdio.h>
#include <switch.h>
#include <sys/stat.h>
namespace CheatManager
{
namespace CheatManager {
void init(void);
void exit(void);
bool loaded(void);

View file

@ -1,44 +1,45 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef CLICKABLE_HPP
#define CLICKABLE_HPP
#include <string>
#include <switch.h>
#include "SDLHelper.hpp"
#include "iclickable.hpp"
#include "status.hpp"
#include "SDLHelper.hpp"
#include <string>
#include <switch.h>
class Clickable : public IClickable<SDL_Color>
{
class Clickable : public IClickable<SDL_Color> {
public:
Clickable(int x, int y, u16 w, u16 h, SDL_Color colorBg, SDL_Color colorText, const std::string& message, bool centered)
: IClickable(x, y, w, h, colorBg, colorText, message, centered) { }
virtual ~Clickable(void) { };
: IClickable(x, y, w, h, colorBg, colorText, message, centered)
{
}
virtual ~Clickable(void){};
void draw(float font, SDL_Color overlay) override;
bool held(void) override;

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef COLORS_HPP
#define COLORS_HPP
@ -31,17 +31,17 @@
#define COLOR_WHITE FC_MakeColor(255, 255, 255, 255)
#define COLOR_BLACK FC_MakeColor(0, 0, 0, 255)
#define COLOR_BLUE FC_MakeColor(29, 50, 243, 255)
#define COLOR_BLUE FC_MakeColor(29, 50, 243, 255)
#define COLOR_GREEN FC_MakeColor(0, 254, 197, 255)
#define COLOR_RED FC_MakeColor(255, 81, 48, 255)
#define COLOR_GOLD FC_MakeColor(255, 215, 0, 255)
#define COLOR_RED FC_MakeColor(255, 81, 48, 255)
#define COLOR_GOLD FC_MakeColor(255, 215, 0, 255)
#define COLOR_GREY_BG FC_MakeColor(51, 51, 51, 255)
#define COLOR_GREY_BG FC_MakeColor(51, 51, 51, 255)
#define COLOR_GREY_DARKER FC_MakeColor(70, 70, 70, 255)
#define COLOR_GREY_DARK FC_MakeColor(79, 79, 79, 255)
#define COLOR_GREY_DARK FC_MakeColor(79, 79, 79, 255)
#define COLOR_GREY_MEDIUM FC_MakeColor(94, 94, 94, 255)
#define COLOR_GREY_LIGHT FC_MakeColor(138, 138, 138, 255)
#define COLOR_HIGHBLUE FC_MakeColor( 48, 65, 106, 255)
#define COLOR_GREY_LIGHT FC_MakeColor(138, 138, 138, 255)
#define COLOR_HIGHBLUE FC_MakeColor(48, 65, 106, 255)
struct Theme {
SDL_Color c0;

View file

@ -1,46 +1,45 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef CONFIGHANDLER_HPP
#define CONFIGHANDLER_HPP
#include "io.hpp"
#include "json.hpp"
#include "util.hpp"
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "json.hpp"
#include "io.hpp"
#include "util.hpp"
extern "C" {
#include "mongoose.h"
}
#define CONFIG_VERSION 2
class Configuration
{
class Configuration {
public:
static Configuration& getInstance(void)
{

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef DIRECTORY_HPP
#define DIRECTORY_HPP
@ -35,26 +35,24 @@
struct DirectoryEntry {
std::string name;
bool directory;
bool directory;
};
class Directory
{
class Directory {
public:
Directory(const std::string& root);
~Directory(void) { };
~Directory(void){};
Result error(void);
Result error(void);
std::string entry(size_t index);
bool folder(size_t index);
bool good(void);
size_t size(void);
bool folder(size_t index);
bool good(void);
size_t size(void);
private:
std::vector
<struct DirectoryEntry> mList;
Result mError;
bool mGood;
std::vector<struct DirectoryEntry> mList;
Result mError;
bool mGood;
};
#endif

View file

@ -1,40 +1,39 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef FILESYSTEM_HPP
#define FILESYSTEM_HPP
#include <switch.h>
namespace FileSystem
{
namespace FileSystem {
Result mount(FsFileSystem* fileSystem, u64 titleID, u128 userID);
Result mount(FsFileSystem* fileSystem, u64 saveID);
int mount(FsFileSystem fs);
void unmount(void);
int mount(FsFileSystem fs);
void unmount(void);
}
#endif

View file

@ -1,39 +1,36 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef GUI_HPP
#define GUI_HPP
#include <math.h>
#include <switch.h>
#include <string.h>
#include "account.hpp"
#include "colors.hpp"
#include "clickable.hpp"
#include "SDLHelper.hpp"
#include "account.hpp"
#include "clickable.hpp"
#include "colors.hpp"
#include "hid.hpp"
#include "main.hpp"
#include "multiselection.hpp"
@ -42,39 +39,40 @@
#include "title.hpp"
#include "types.hpp"
#include "util.hpp"
#include <math.h>
#include <string.h>
#include <switch.h>
namespace Gui
{
bool init(void);
void exit(void);
void draw(void);
namespace Gui {
bool init(void);
void exit(void);
void draw(void);
void showInfo(const std::string& message);
void showError(Result res, const std::string& message);
void showInfo(const std::string& message);
void showError(Result res, const std::string& message);
size_t count(entryType_t type);
void entryType(entryType_t type);
size_t index(entryType_t type);
void index(entryType_t type, size_t i);
bool isBackupReleased(void);
bool isRestoreReleased(void);
bool isCheatReleased(void);
size_t count(entryType_t type);
void entryType(entryType_t type);
size_t index(entryType_t type);
void index(entryType_t type, size_t i);
bool isBackupReleased(void);
bool isRestoreReleased(void);
bool isCheatReleased(void);
std::string nameFromCell(size_t index);
void resetIndex(entryType_t type);
void updateButtons(void);
void updateSelector(void);
void resetIndex(entryType_t type);
void updateButtons(void);
void updateSelector(void);
bool askForConfirmation(const std::string& text);
void drawCopy(const std::string& src, u64 offset, u64 size);
bool askForConfirmation(const std::string& text);
void drawCopy(const std::string& src, u64 offset, u64 size);
void addSelectedEntry(size_t idx);
void clearSelectedEntries(void);
bool multipleSelectionEnabled(void);
std::vector
<size_t> selectedEntries(void);
void addSelectedEntry(size_t idx);
void clearSelectedEntries(void);
bool multipleSelectionEnabled(void);
std::vector<size_t> selectedEntries(void);
bool getPKSMBridgeFlag(void);
void setPKSMBridgeFlag(bool f);
bool getPKSMBridgeFlag(void);
void setPKSMBridgeFlag(bool f);
}
#endif

View file

@ -1,57 +1,46 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef HID_HPP
#define HID_HPP
#include <switch.h>
#include "ihid.hpp"
#include <switch.h>
class HidVertical : public IHidVertical
{
class HidVertical : public IHidVertical {
public:
HidVertical(size_t entries, size_t columns)
: IHidVertical(entries, columns) { mDelayTicks = 2500000; }
HidVertical(size_t entries, size_t columns) : IHidVertical(entries, columns) { mDelayTicks = 2500000; }
virtual ~HidVertical(void) { }
virtual ~HidVertical(void) {}
u64 down(void) override
{
return hidKeysDown(CONTROLLER_P1_AUTO);
}
u64 down(void) override { return hidKeysDown(CONTROLLER_P1_AUTO); }
u64 held(void) override
{
return hidKeysHeld(CONTROLLER_P1_AUTO);
}
u64 held(void) override { return hidKeysHeld(CONTROLLER_P1_AUTO); }
u64 tick(void) override
{
return armGetSystemTick();
}
u64 tick(void) override { return armGetSystemTick(); }
u64 _KEY_ZL(void) override { return 0; }
u64 _KEY_ZR(void) override { return 0; }
@ -61,28 +50,17 @@ public:
u64 _KEY_DOWN(void) override { return KEY_DOWN; }
};
class HidHorizontal : public IHidHorizontal
{
class HidHorizontal : public IHidHorizontal {
public:
HidHorizontal(size_t entries, size_t columns)
: IHidHorizontal(entries, columns) { mDelayTicks = 2500000; }
HidHorizontal(size_t entries, size_t columns) : IHidHorizontal(entries, columns) { mDelayTicks = 2500000; }
virtual ~HidHorizontal(void) { }
virtual ~HidHorizontal(void) {}
u64 down(void) override
{
return hidKeysDown(CONTROLLER_P1_AUTO);
}
u64 down(void) override { return hidKeysDown(CONTROLLER_P1_AUTO); }
u64 held(void) override
{
return hidKeysHeld(CONTROLLER_P1_AUTO);
}
u64 held(void) override { return hidKeysHeld(CONTROLLER_P1_AUTO); }
u64 tick(void) override
{
return armGetSystemTick();
}
u64 tick(void) override { return armGetSystemTick(); }
u64 _KEY_ZL(void) override { return 0; }
u64 _KEY_ZR(void) override { return 0; }

View file

@ -1,54 +1,53 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef IO_HPP
#define IO_HPP
#include "KeyboardManager.hpp"
#include "directory.hpp"
#include "gui.hpp"
#include <dirent.h>
#include <switch.h>
#include <sys/stat.h>
#include <unistd.h>
#include <utility>
#include "directory.hpp"
#include "gui.hpp"
#include "KeyboardManager.hpp"
#define BUFFER_SIZE 0x80000
namespace io
{
void backup(size_t index, u128 uid);
void restore(size_t index, u128 uid);
namespace io {
void backup(size_t index, u128 uid);
void restore(size_t index, u128 uid);
Result copyDirectory(const std::string& srcPath, const std::string& dstPath);
void copyFile(const std::string& srcPath, const std::string& dstPath);
void copyFile(const std::string& srcPath, const std::string& dstPath);
Result createDirectory(const std::string& path);
Result deleteFolderRecursively(const std::string& path);
bool directoryExists(const std::string& path);
bool fileExists(const std::string& path);
bool directoryExists(const std::string& path);
bool fileExists(const std::string& path);
}
#endif

View file

@ -1,38 +1,38 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef MAIN_HPP
#define MAIN_HPP
#include <switch.h>
#include "io.hpp"
#include "pksmbridge.hpp"
#include "status.hpp"
#include "title.hpp"
#include "util.hpp"
#include "pksmbridge.hpp"
#include <switch.h>
extern u128 g_currentUId;
extern bool g_notificationLedAvailable;

View file

@ -1,41 +1,41 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include <switch.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string>
#include <utility>
#include "gui.hpp"
#include "KeyboardManager.hpp"
#include "gui.hpp"
#include <arpa/inet.h>
#include <errno.h>
#include <netinet/in.h>
#include <string.h>
#include <string>
#include <switch.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <utility>
#define PKSM_PORT 34567

View file

@ -1,53 +1,48 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef SCROLLABLE_HPP
#define SCROLLABLE_HPP
#include <switch.h>
#include <vector>
#include "iscrollable.hpp"
#include "SDLHelper.hpp"
#include "clickable.hpp"
#include "colors.hpp"
#include "SDLHelper.hpp"
#include "hid.hpp"
#include "iscrollable.hpp"
#include <switch.h>
#include <vector>
class Scrollable : public IScrollable<SDL_Color>
{
class Scrollable : public IScrollable<SDL_Color> {
public:
Scrollable(u32 x, u32 y, u32 w, u32 h, size_t visibleEntries)
: IScrollable(x, y, w, h, visibleEntries)
Scrollable(u32 x, u32 y, u32 w, u32 h, size_t visibleEntries) : IScrollable(x, y, w, h, visibleEntries)
{
mHid = new HidVertical(visibleEntries, 1);
}
virtual ~Scrollable(void)
{
delete mHid;
};
virtual ~Scrollable(void) { delete mHid; };
void draw(bool condition = false) override;
void setIndex(size_t i);

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
extern bool g_backupScrollEnabled;
extern float g_currentTime;

View file

@ -1,89 +1,85 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef TITLE_HPP
#define TITLE_HPP
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <switch.h>
#include <utility>
#include <vector>
#include <unordered_map>
#include "SDLHelper.hpp"
#include "configuration.hpp"
#include "filesystem.hpp"
#include "io.hpp"
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <switch.h>
#include <unordered_map>
#include <utility>
#include <vector>
class Title
{
class Title {
public:
void init(u8 saveDataType, u64 titleid, u128 userID, const std::string& name, const std::string& author);
~Title(void) { };
~Title(void){};
std::string author(void);
std::string author(void);
std::pair<std::string, std::string> displayName(void);
SDL_Texture* icon(void);
u64 id(void);
std::string name(void);
std::string path(void);
std::string fullPath(size_t index);
void refreshDirectories(void);
u64 saveId();
void saveId(u64 id);
std::vector
<std::string> saves(void);
u8 saveDataType(void);
bool systemSave(void);
u128 userId(void);
std::string userName(void);
SDL_Texture* icon(void);
u64 id(void);
std::string name(void);
std::string path(void);
std::string fullPath(size_t index);
void refreshDirectories(void);
u64 saveId();
void saveId(u64 id);
std::vector<std::string> saves(void);
u8 saveDataType(void);
bool systemSave(void);
u128 userId(void);
std::string userName(void);
private:
u64 mId;
u64 mSaveId;
u128 mUserId;
std::string mUserName;
std::string mName;
std::string mSafeName;
std::string mAuthor;
std::string mPath;
std::vector
<std::string> mSaves;
std::vector
<std::string> mFullSavePaths;
u8 mSaveDataType;
u64 mId;
u64 mSaveId;
u128 mUserId;
std::string mUserName;
std::string mName;
std::string mSafeName;
std::string mAuthor;
std::string mPath;
std::vector<std::string> mSaves;
std::vector<std::string> mFullSavePaths;
u8 mSaveDataType;
};
void getTitle(Title &dst, u128 uid, size_t i);
void getTitle(Title& dst, u128 uid, size_t i);
size_t getTitleCount(u128 uid);
void loadTitles(void);
void refreshDirectories(u64 id);
bool favorite(u128 uid, int i);
void freeIcons(void);
void loadTitles(void);
void refreshDirectories(u64 id);
bool favorite(u128 uid, int i);
void freeIcons(void);
SDL_Texture* smallIcon(u128 uid, size_t i);
std::unordered_map<std::string, std::string> getCompleteTitleList(void);

View file

@ -1,9 +1,6 @@
#ifndef TYPES_HPP
#define TYPES_HPP
typedef enum {
TITLES,
CELLS
} entryType_t;
typedef enum { TITLES, CELLS } entryType_t;
#endif

View file

@ -1,54 +1,53 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#ifndef UTIL_HPP
#define UTIL_HPP
#include <switch.h>
#include <sys/stat.h>
#include "common.hpp"
#include "account.hpp"
#include "cheatmanager.hpp"
#include "common.hpp"
#include "gui.hpp"
#include "io.hpp"
#include "cheatmanager.hpp"
#include <switch.h>
#include <sys/stat.h>
// debug
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/errno.h>
#include <sys/socket.h>
void servicesExit(void);
void servicesExit(void);
Result servicesInit(void);
HidsysNotificationLedPattern blinkLedPattern(u8 times);
void blinkLed(u8 times);
namespace StringUtils
{
std::string removeAccents(std::string str);
std::string removeNotAscii(std::string str);
namespace StringUtils {
std::string removeAccents(std::string str);
std::string removeNotAscii(std::string str);
std::u16string UTF8toUTF16(const char* src);
}

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "KeyboardManager.hpp"
@ -31,8 +31,7 @@ KeyboardManager::KeyboardManager(void)
systemKeyboardAvailable = false;
SwkbdConfig kbd;
res = swkbdCreate(&kbd, 0);
if (R_SUCCEEDED(res))
{
if (R_SUCCEEDED(res)) {
systemKeyboardAvailable = true;
swkbdClose(&kbd);
}
@ -40,19 +39,16 @@ KeyboardManager::KeyboardManager(void)
std::pair<bool, std::string> KeyboardManager::keyboard(const std::string& suggestion)
{
if (systemKeyboardAvailable)
{
if (systemKeyboardAvailable) {
char tmpoutstr[CUSTOM_PATH_LEN] = {0};
SwkbdConfig kbd;
if (R_SUCCEEDED(swkbdCreate(&kbd, 0)))
{
if (R_SUCCEEDED(swkbdCreate(&kbd, 0))) {
swkbdConfigMakePresetDefault(&kbd);
swkbdConfigSetInitialText(&kbd, suggestion.c_str());
swkbdConfigSetStringLenMax(&kbd, CUSTOM_PATH_LEN);
Result res = swkbdShow(&kbd, tmpoutstr, CUSTOM_PATH_LEN);
swkbdClose(&kbd);
if (R_SUCCEEDED(res))
{
if (R_SUCCEEDED(res)) {
return std::make_pair(true, std::string(tmpoutstr));
}
}

View file

@ -11,10 +11,10 @@ static std::unordered_map<int, FC_Font*> s_fonts;
static FC_Font* getFontFromMap(int size)
{
std::unordered_map<int, FC_Font*>::const_iterator got = s_fonts.find(size);
if (got == s_fonts.end() || got->second == NULL)
{
if (got == s_fonts.end() || got->second == NULL) {
FC_Font* f = FC_CreateFont();
FC_LoadFont_RW(f, s_renderer, SDL_RWFromMem((void*)fontData.address, fontData.size), SDL_RWFromMem((void*)fontExtData.address, fontExtData.size), 1, size, FC_MakeColor(0, 0, 0, 255), TTF_STYLE_NORMAL);
FC_LoadFont_RW(f, s_renderer, SDL_RWFromMem((void*)fontData.address, fontData.size),
SDL_RWFromMem((void*)fontExtData.address, fontExtData.size), 1, size, FC_MakeColor(0, 0, 0, 255), TTF_STYLE_NORMAL);
s_fonts.insert({size, f});
return f;
}
@ -23,29 +23,25 @@ static FC_Font* getFontFromMap(int size)
bool SDLH_Init(void)
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0)
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) {
fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
return false;
}
s_window = SDL_CreateWindow("Checkpoint", 0, 0, 1280, 720, SDL_WINDOW_FULLSCREEN);
if (!s_window)
{
if (!s_window) {
fprintf(stderr, "SDL_CreateWindow: %s\n", SDL_GetError());
return false;
}
s_renderer = SDL_CreateRenderer(s_window, 0, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (!s_renderer)
{
if (!s_renderer) {
fprintf(stderr, "SDL_CreateRenderer: %s\n", SDL_GetError());
return false;
}
SDL_SetRenderDrawBlendMode(s_renderer, SDL_BLENDMODE_BLEND);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
const int img_flags = IMG_INIT_PNG | IMG_INIT_JPG;
if ((IMG_Init(img_flags) & img_flags) != img_flags)
{
if ((IMG_Init(img_flags) & img_flags) != img_flags) {
fprintf(stderr, "IMG_Init: %s\n", IMG_GetError());
return false;
}
@ -55,14 +51,13 @@ bool SDLH_Init(void)
plGetSharedFontByType(&fontData, PlSharedFontType_Standard);
plGetSharedFontByType(&fontExtData, PlSharedFontType_NintendoExt);
return true;
}
void SDLH_Exit(void)
{
for (auto& value : s_fonts)
{
for (auto& value : s_fonts) {
FC_FreeFont(value.second);
}
@ -91,7 +86,10 @@ void SDLH_Render(void)
void SDLH_DrawRect(int x, int y, int w, int h, SDL_Color color)
{
SDL_Rect rect;
rect.x = x; rect.y = y; rect.w = w; rect.h = h;
rect.x = x;
rect.y = y;
rect.w = w;
rect.h = h;
SDL_SetRenderDrawColor(s_renderer, color.r, color.g, color.b, color.a);
SDL_RenderFillRect(s_renderer, &rect);
}
@ -113,10 +111,9 @@ void SDLH_DrawTextBox(int size, int x, int y, SDL_Color color, int max, const ch
void SDLH_LoadImage(SDL_Texture** texture, char* path)
{
SDL_Surface* loaded_surface = NULL;
loaded_surface = IMG_Load(path);
loaded_surface = IMG_Load(path);
if (loaded_surface)
{
if (loaded_surface) {
Uint32 colorkey = SDL_MapRGB(loaded_surface->format, 0, 0, 0);
SDL_SetColorKey(loaded_surface, SDL_TRUE, colorkey);
*texture = SDL_CreateTextureFromSurface(s_renderer, loaded_surface);
@ -128,10 +125,9 @@ void SDLH_LoadImage(SDL_Texture** texture, char* path)
void SDLH_LoadImage(SDL_Texture** texture, u8* buff, size_t size)
{
SDL_Surface* loaded_surface = NULL;
loaded_surface = IMG_Load_RW(SDL_RWFromMem(buff, size), 1);
loaded_surface = IMG_Load_RW(SDL_RWFromMem(buff, size), 1);
if (loaded_surface)
{
if (loaded_surface) {
Uint32 colorkey = SDL_MapRGB(loaded_surface->format, 0, 0, 0);
SDL_SetColorKey(loaded_surface, SDL_TRUE, colorkey);
*texture = SDL_CreateTextureFromSurface(s_renderer, loaded_surface);
@ -143,7 +139,8 @@ void SDLH_LoadImage(SDL_Texture** texture, u8* buff, size_t size)
void SDLH_DrawImage(SDL_Texture* texture, int x, int y)
{
SDL_Rect position;
position.x = x; position.y = y;
position.x = x;
position.y = y;
SDL_QueryTexture(texture, NULL, NULL, &position.w, &position.h);
SDL_RenderCopy(s_renderer, texture, NULL, &position);
}
@ -151,15 +148,20 @@ void SDLH_DrawImage(SDL_Texture* texture, int x, int y)
void SDLH_DrawImageScale(SDL_Texture* texture, int x, int y, int w, int h)
{
SDL_Rect position;
position.x = x; position.y = y; position.w = w; position.h = h;
position.x = x;
position.y = y;
position.w = w;
position.h = h;
SDL_RenderCopy(s_renderer, texture, NULL, &position);
}
void SDLH_GetTextDimensions(int size, const char* text, u32* w, u32* h)
{
FC_Font* f = getFontFromMap(size);
if (w != NULL) *w = FC_GetWidth(f, text);
if (h != NULL) *h = FC_GetHeight(f, text);
if (w != NULL)
*w = FC_GetWidth(f, text);
if (h != NULL)
*h = FC_GetHeight(f, text);
}
void SDLH_DrawIcon(std::string icon, int x, int y)
@ -168,7 +170,8 @@ void SDLH_DrawIcon(std::string icon, int x, int y)
if (icon.compare("checkbox") == 0) {
t = s_checkbox;
SDLH_DrawRect(x + 8, y + 8, 24, 24, theme().c6);
} else if (icon.compare("star") == 0) {
}
else if (icon.compare("star") == 0) {
t = s_star;
}
@ -180,16 +183,18 @@ void SDLH_DrawIcon(std::string icon, int x, int y)
void drawPulsingOutline(u32 x, u32 y, u16 w, u16 h, u8 size, SDL_Color color)
{
float highlight_multiplier = fmax(0.0, fabs(fmod(g_currentTime, 1.0) - 0.5) / 0.5);
color = FC_MakeColor(color.r + (255 - color.r) * highlight_multiplier, color.g + (255 - color.g) * highlight_multiplier, color.b + (255 - color.b) * highlight_multiplier, 255);
SDLH_DrawRect(x - size, y - size, w + 2*size, size, color); // top
SDLH_DrawRect(x - size, y, size, h, color); // left
SDLH_DrawRect(x + w, y, size, h, color); // right
SDLH_DrawRect(x - size, y + h, w + 2*size, size, color); // bottom
color = FC_MakeColor(color.r + (255 - color.r) * highlight_multiplier, color.g + (255 - color.g) * highlight_multiplier,
color.b + (255 - color.b) * highlight_multiplier, 255);
SDLH_DrawRect(x - size, y - size, w + 2 * size, size, color); // top
SDLH_DrawRect(x - size, y, size, h, color); // left
SDLH_DrawRect(x + w, y, size, h, color); // right
SDLH_DrawRect(x - size, y + h, w + 2 * size, size, color); // bottom
}
void drawPulsingRect(int x, int y, int w, int h, SDL_Color color)
{
float highlight_multiplier = fmax(0.0, fabs(fmod(g_currentTime, 1.0) - 0.5) / 0.5);
color = FC_MakeColor(color.r + (255 - color.r) * highlight_multiplier, color.g + (255 - color.g) * highlight_multiplier, color.b + (255 - color.b) * highlight_multiplier, 255);
color = FC_MakeColor(color.r + (255 - color.r) * highlight_multiplier, color.g + (255 - color.g) * highlight_multiplier,
color.b + (255 - color.b) * highlight_multiplier, 255);
SDLH_DrawRect(x, y, w, h, color);
}

File diff suppressed because it is too large Load diff

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "account.hpp"
@ -35,8 +35,7 @@ Result Account::init(void)
void Account::exit(void)
{
for (auto& value : mUsers)
{
for (auto& value : mUsers) {
SDL_DestroyTexture(value.second.icon);
}
accountExit();
@ -45,8 +44,7 @@ void Account::exit(void)
std::vector<u128> Account::ids(void)
{
std::vector<u128> v;
for (auto& value : mUsers)
{
for (auto& value : mUsers) {
v.push_back(value.second.id);
}
return v;
@ -54,23 +52,19 @@ std::vector<u128> Account::ids(void)
static User getUser(u128 id)
{
User user{ id, "", NULL };
User user{id, "", NULL};
AccountProfile profile;
AccountProfileBase profilebase;
memset(&profilebase, 0, sizeof(profilebase));
if (R_SUCCEEDED(accountGetProfile(&profile, id)) &&
R_SUCCEEDED(accountProfileGet(&profile, NULL, &profilebase)))
{
if (R_SUCCEEDED(accountGetProfile(&profile, id)) && R_SUCCEEDED(accountProfileGet(&profile, NULL, &profilebase))) {
user.name = std::string(profilebase.username, 0x20);
//load icon
// load icon
u8* buffer;
size_t image_size, real_size;
if (R_SUCCEEDED(accountProfileGetImageSize(&profile, &image_size)) &&
(buffer = (u8*)malloc(image_size)) != NULL &&
R_SUCCEEDED(accountProfileLoadImage(&profile, buffer, image_size, &real_size)))
{
if (R_SUCCEEDED(accountProfileGetImageSize(&profile, &image_size)) && (buffer = (u8*)malloc(image_size)) != NULL &&
R_SUCCEEDED(accountProfileLoadImage(&profile, buffer, image_size, &real_size))) {
SDLH_LoadImage(&user.icon, buffer, image_size);
free(buffer);
}
@ -83,8 +77,7 @@ static User getUser(u128 id)
std::string Account::username(u128 id)
{
std::map<u128, User>::const_iterator got = mUsers.find(id);
if (got == mUsers.end())
{
if (got == mUsers.end()) {
User user = getUser(id);
mUsers.insert({id, user});
return user.name;
@ -96,8 +89,7 @@ std::string Account::username(u128 id)
SDL_Texture* Account::icon(u128 id)
{
std::map<u128, User>::const_iterator got = mUsers.find(id);
if (got == mUsers.end())
{
if (got == mUsers.end()) {
User user = getUser(id);
mUsers.insert({id, user});
return user.icon;
@ -120,7 +112,7 @@ u128 Account::selectAccount(void)
LibAppletArgs args;
u8 indata[0xA0] = {0};
indata[0x96] = 1;
indata[0x96] = 1;
appletCreateLibraryApplet(&aph, AppletId_playerSelect, LibAppletMode_AllForeground);
libappletArgsCreate(&args, 0);
@ -132,7 +124,8 @@ u128 Account::selectAccount(void)
appletHolderPushInData(&aph, &hast1);
appletHolderStart(&aph);
while (appletHolderWaitInteractiveOut(&aph));
while (appletHolderWaitInteractiveOut(&aph))
;
appletHolderJoin(&aph);
appletHolderPopOutData(&aph, &ast);

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "cheatmanager.hpp"
@ -36,35 +36,30 @@ void CheatManager::init(void)
{
Gui::updateButtons();
if (io::fileExists("/switch/Checkpoint/cheats.json"))
{
if (io::fileExists("/switch/Checkpoint/cheats.json")) {
const std::string path = "/switch/Checkpoint/cheats.json";
FILE* in = fopen(path.c_str(), "rt");
if (in != NULL)
{
FILE* in = fopen(path.c_str(), "rt");
if (in != NULL) {
mCheats = nlohmann::json::parse(in, nullptr, false);
fclose(in);
mLoaded = true;
}
}
else
{
else {
const std::string path = "romfs:/cheats/cheats.json.bz2";
// load compressed archive in memory
FILE* f = fopen(path.c_str(), "rb");
if (f != NULL)
{
if (f != NULL) {
fseek(f, 0, SEEK_END);
u32 size = ftell(f);
unsigned int destLen = 1024*1024;
char* s = new char[size];
char* d = new char[destLen]();
u32 size = ftell(f);
unsigned int destLen = 1024 * 1024;
char* s = new char[size];
char* d = new char[destLen]();
rewind(f);
fread(s, 1, size, f);
int r = BZ2_bzBuffToBuffDecompress(d, &destLen, s, size, 0, 0);
if (r == BZ_OK)
{
if (r == BZ_OK) {
mCheats = nlohmann::json::parse(d);
mLoaded = true;
}
@ -74,14 +69,11 @@ void CheatManager::init(void)
fclose(f);
}
}
Gui::updateButtons();
}
void CheatManager::exit(void)
{
}
void CheatManager::exit(void) {}
bool CheatManager::loaded(void)
{
@ -99,18 +91,14 @@ void CheatManager::manageCheats(const std::string& key)
std::string root = StringUtils::format("/atmosphere/titles/%s/cheats", key.c_str());
Directory dir(root);
if (dir.good())
{
for (size_t i = 0; i < dir.size(); i++)
{
if (!dir.folder(i))
{
if (dir.good()) {
for (size_t i = 0; i < dir.size(); i++) {
if (!dir.folder(i)) {
FILE* f = fopen((root + "/" + dir.entry(i)).c_str(), "r");
if (f != NULL)
{
if (f != NULL) {
fseek(f, 0, SEEK_END);
u32 size = ftell(f);
char* s = new char[size];
char* s = new char[size];
rewind(f);
fread(s, 1, size, f);
existingCheat += "\n" + std::string(s);
@ -121,17 +109,14 @@ void CheatManager::manageCheats(const std::string& key)
}
}
size_t i = 0;
size_t i = 0;
size_t currentIndex = i;
Scrollable* s = new Scrollable(90, 20, 1100, 640, 16);
for (auto it = mCheats[key].begin(); it != mCheats[key].end(); ++it)
{
Scrollable* s = new Scrollable(90, 20, 1100, 640, 16);
for (auto it = mCheats[key].begin(); it != mCheats[key].end(); ++it) {
std::string buildid = it.key();
for (auto it2 = mCheats[key][buildid].begin(); it2 != mCheats[key][buildid].end(); ++it2)
{
for (auto it2 = mCheats[key][buildid].begin(); it2 != mCheats[key][buildid].end(); ++it2) {
std::string value = it2.key();
if (existingCheat.find(value) != std::string::npos)
{
if (existingCheat.find(value) != std::string::npos) {
value = SELECTED_MAGIC + value;
}
s->push_back(COLOR_GREY_DARKER, COLOR_WHITE, value, i == 0);
@ -139,55 +124,43 @@ void CheatManager::manageCheats(const std::string& key)
}
}
while(appletMainLoop())
{
while (appletMainLoop()) {
hidScanInput();
if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_B)
{
if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_B) {
break;
}
if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_A)
{
if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_A) {
std::string cellName = s->cellName(s->index());
if (cellName.find(SELECTED_MAGIC, 0) == 0)
{
if (cellName.find(SELECTED_MAGIC, 0) == 0) {
// cheat was already selected
cellName = cellName.substr(strlen(SELECTED_MAGIC), cellName.length());
}
else
{
else {
cellName = SELECTED_MAGIC + cellName;
}
s->text(s->index(), cellName);
}
if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_Y)
{
if (multiSelected)
{
for (size_t i = 0; i < s->size(); i++)
{
if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_Y) {
if (multiSelected) {
for (size_t i = 0; i < s->size(); i++) {
std::string cellName = s->cellName(i);
if (cellName.find(SELECTED_MAGIC, 0) == 0)
{
if (cellName.find(SELECTED_MAGIC, 0) == 0) {
cellName = cellName.substr(strlen(SELECTED_MAGIC), cellName.length());
s->text(i, cellName);
}
s->text(i, cellName);
}
}
multiSelected = false;
}
else
{
for (size_t i = 0; i < s->size(); i++)
{
else {
for (size_t i = 0; i < s->size(); i++) {
std::string cellName = s->cellName(i);
if (cellName.find(SELECTED_MAGIC, 0) != 0)
{
if (cellName.find(SELECTED_MAGIC, 0) != 0) {
cellName = SELECTED_MAGIC + cellName;
s->text(i, cellName);
}
s->text(i, cellName);
}
}
multiSelected = true;
}
@ -205,12 +178,12 @@ void CheatManager::manageCheats(const std::string& key)
SDLH_DrawRect(86, 16, 1108, 680, COLOR_GREY_DARK);
s->draw(true);
SDLH_DrawText(20, ceilf(1190 - width), ceilf(664 + (32 - height) / 2), COLOR_WHITE, page.c_str());
SDLH_DrawText(20, 94, ceilf(664 + (32 - height) / 2), COLOR_WHITE, multiSelected ? "\ue003 to deselect all cheats" : "\ue003 to select all cheats");
SDLH_DrawText(
20, 94, ceilf(664 + (32 - height) / 2), COLOR_WHITE, multiSelected ? "\ue003 to deselect all cheats" : "\ue003 to select all cheats");
SDLH_Render();
}
if (Gui::askForConfirmation("Do you want to store the cheat file?"))
{
if (Gui::askForConfirmation("Do you want to store the cheat file?")) {
save(key, s);
}
@ -219,26 +192,21 @@ void CheatManager::manageCheats(const std::string& key)
void CheatManager::save(const std::string& key, Scrollable* s)
{
std::string idfolder = StringUtils::format("/atmosphere/titles/%s", key.c_str());
std::string idfolder = StringUtils::format("/atmosphere/titles/%s", key.c_str());
std::string rootfolder = idfolder + "/cheats";
mkdir(idfolder.c_str(), 777);
mkdir(rootfolder.c_str(), 777);
for (auto it = mCheats[key].begin(); it != mCheats[key].end(); ++it)
{
std::string buildid = it.key();
for (auto it = mCheats[key].begin(); it != mCheats[key].end(); ++it) {
std::string buildid = it.key();
std::string cheatFile = "";
for (size_t i = 0; i < s->size(); i++)
{
for (size_t i = 0; i < s->size(); i++) {
std::string cellName = s->cellName(i);
if (cellName.find(SELECTED_MAGIC, 0) == 0)
{
if (cellName.find(SELECTED_MAGIC, 0) == 0) {
cellName = cellName.substr(strlen(SELECTED_MAGIC), cellName.length());
if (mCheats[key][buildid].find(cellName) != mCheats[key][buildid].end())
{
if (mCheats[key][buildid].find(cellName) != mCheats[key][buildid].end()) {
cheatFile += cellName + "\n";
for (auto& it2 : mCheats[key][buildid][cellName])
{
for (auto& it2 : mCheats[key][buildid][cellName]) {
cheatFile += it2.get<std::string>() + "\n";
}
cheatFile += "\n";
@ -247,13 +215,11 @@ void CheatManager::save(const std::string& key, Scrollable* s)
}
FILE* f = fopen((rootfolder + "/" + buildid + ".txt").c_str(), "w");
if (f != NULL)
{
if (f != NULL) {
fwrite(cheatFile.c_str(), 1, cheatFile.length(), f);
fclose(f);
}
else
{
else {
Gui::showError(errno, "Failed to write cheat file\nto the sd card");
}
}

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "clickable.hpp"
@ -30,29 +30,27 @@ bool Clickable::held()
{
touchPosition touch;
hidTouchRead(&touch, 0);
return ((hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH) && (int)touch.px > mx && (int)touch.px < mx+mw && (int)touch.py > my && (int)touch.py < my+mh);
return ((hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH) && (int)touch.px > mx && (int)touch.px < mx + mw && (int)touch.py > my &&
(int)touch.py < my + mh);
}
bool Clickable::released(void)
{
touchPosition touch;
hidTouchRead(&touch, 0);
const bool on = (int)touch.px > mx && (int)touch.px < mx+mw && (int)touch.py > my && (int)touch.py < my+mh;
if (on)
{
hidTouchRead(&touch, 0);
const bool on = (int)touch.px > mx && (int)touch.px < mx + mw && (int)touch.py > my && (int)touch.py < my + mh;
if (on) {
mOldPressed = true;
}
else
{
if (mOldPressed && !(touch.px > 0 || touch.py > 0))
{
mOldPressed = false;
else {
if (mOldPressed && !(touch.px > 0 || touch.py > 0)) {
mOldPressed = false;
return true;
}
mOldPressed = false;
}
return false;
}
@ -63,16 +61,14 @@ void Clickable::draw(float font, SDL_Color overlay)
const u32 messageWidth = mCentered ? textw : mw - (mSelected ? 20 : 8);
SDLH_DrawRect(mx, my, mw, mh, mColorBg);
if (mCanChangeColorWhenSelected && held())
{
if (mCanChangeColorWhenSelected && held()) {
SDLH_DrawRect(mx, my, mw, mh, FC_MakeColor(overlay.r, overlay.g, overlay.b, 100));
}
if (mSelected)
{
if (mSelected) {
SDLH_DrawRect(mx + 4, my + 6, 4, mh - 12, COLOR_WHITE);
SDLH_DrawRect(mx, my, mw, mh, FC_MakeColor(overlay.r, overlay.g, overlay.b, 100));
}
SDLH_DrawTextBox(font, mx + (mSelected ? 8 : 0) + (mw - messageWidth)/2, my + (mh - texth)/2 + 2, mColorText, mw - 4*2, mText.c_str());
SDLH_DrawTextBox(font, mx + (mSelected ? 8 : 0) + (mw - messageWidth) / 2, my + (mh - texth) / 2 + 2, mColorText, mw - 4 * 2, mText.c_str());
}
void Clickable::drawOutline(SDL_Color color)

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "colors.hpp"
@ -40,8 +40,10 @@ static struct Theme currentTheme = defaultTheme;
void theme(int t)
{
switch(t) {
default: currentTheme = defaultTheme; break;
switch (t) {
default:
currentTheme = defaultTheme;
break;
}
}

View file

@ -1,75 +1,74 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "configuration.hpp"
static struct mg_mgr mgr;
static struct mg_connection *nc;
static struct mg_connection* nc;
static struct mg_serve_http_opts s_http_server_opts;
static const char *s_http_port = "8000";
static const char* s_http_port = "8000";
static void handle_populate(struct mg_connection *nc, struct http_message *hm)
static void handle_populate(struct mg_connection* nc, struct http_message* hm)
{
// populate gets called at startup, assume a new connection has been started
blinkLed(2);
auto json = Configuration::getInstance().getJson();
auto map = getCompleteTitleList();
auto json = Configuration::getInstance().getJson();
auto map = getCompleteTitleList();
json["title_list"] = map;
std::string body = json.dump();
mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%.*s",
(unsigned long)body.length(), (int)body.length(), body.c_str());
std::string body = json.dump();
mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%.*s", (unsigned long)body.length(), (int)body.length(), body.c_str());
}
static void handle_save(struct mg_connection *nc, struct http_message *hm)
static void handle_save(struct mg_connection* nc, struct http_message* hm)
{
FILE* f = fopen(Configuration::getInstance().BASEPATH.c_str(), "w");
if (f != NULL)
{
if (f != NULL) {
fwrite(hm->body.p, 1, hm->body.len, f);
fclose(f);
}
Configuration::getInstance().load();
Configuration::getInstance().parse();
// Send response
mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%.*s",
(unsigned long) hm->body.len, (int) hm->body.len, hm->body.p);
mg_printf(nc, "HTTP/1.1 200 OK\r\nContent-Length: %lu\r\n\r\n%.*s", (unsigned long)hm->body.len, (int)hm->body.len, hm->body.p);
}
static void ev_handler(struct mg_connection *nc, int ev, void *ev_data)
static void ev_handler(struct mg_connection* nc, int ev, void* ev_data)
{
struct http_message *hm = (struct http_message *) ev_data;
struct http_message* hm = (struct http_message*)ev_data;
switch (ev) {
case MG_EV_HTTP_REQUEST:
if (mg_vcmp(&hm->uri, "/save") == 0) {
handle_save(nc, hm);
} else if (mg_vcmp(&hm->uri, "/populate") == 0) {
}
else if (mg_vcmp(&hm->uri, "/populate") == 0) {
handle_populate(nc, hm);
} else {
}
else {
mg_serve_http(nc, hm, s_http_server_opts);
}
break;
@ -81,8 +80,7 @@ static void ev_handler(struct mg_connection *nc, int ev, void *ev_data)
Configuration::Configuration(void)
{
// check for existing config.json files on the sd card, BASEPATH
if (!io::fileExists(BASEPATH))
{
if (!io::fileExists(BASEPATH)) {
store();
}
@ -90,29 +88,24 @@ Configuration::Configuration(void)
load();
bool updateJson = false;
if (mJson.find("version") == mJson.end())
{
if (mJson.find("version") == mJson.end()) {
// if config is present but is < 3.4.2, override it
store();
}
else
{
else {
// 3.4.2 -> 3.5.0
if (mJson["version"] < 2)
{
if (mJson["version"] < 2) {
mJson["favorites"] = nlohmann::json::array();
updateJson = true;
updateJson = true;
}
// 3.5.0 -> 3.5.1
if (mJson["version"] < 3)
{
if (mJson["version"] < 3) {
mJson["pksm-bridge"] = true;
updateJson = true;
updateJson = true;
}
}
if (updateJson)
{
if (updateJson) {
mJson["version"] = CONFIG_VERSION;
save();
}
@ -124,7 +117,7 @@ Configuration::Configuration(void)
nc = mg_bind(&mgr, s_http_port, ev_handler);
mg_set_protocol_http_websocket(nc);
s_http_server_opts.document_root = "romfs:/web_root";
s_http_server_opts.auth_domain = "flagbrew.org";
s_http_server_opts.auth_domain = "flagbrew.org";
}
Configuration::~Configuration(void)
@ -135,8 +128,7 @@ Configuration::~Configuration(void)
void Configuration::store(void)
{
FILE* in = fopen("romfs:/config.json", "rt");
if (in != NULL)
{
if (in != NULL) {
nlohmann::json src = nlohmann::json::parse(in, nullptr, false);
fclose(in);
@ -145,8 +137,7 @@ void Configuration::store(void)
size_t size = writeData.size();
FILE* out = fopen(BASEPATH.c_str(), "wt");
if (out != NULL)
{
if (out != NULL) {
fwrite(writeData.c_str(), 1, size, out);
fclose(out);
}
@ -177,7 +168,7 @@ bool Configuration::isPKSMBridgeEnabled(void)
void Configuration::pollServer(void)
{
mg_mgr_poll(&mgr, 1000/60);
mg_mgr_poll(&mgr, 1000 / 60);
}
void Configuration::save(void)
@ -187,8 +178,7 @@ void Configuration::save(void)
size_t size = writeData.size();
FILE* out = fopen(BASEPATH.c_str(), "wt");
if (out != NULL)
{
if (out != NULL) {
fwrite(writeData.c_str(), 1, size, out);
fclose(out);
}
@ -197,8 +187,7 @@ void Configuration::save(void)
void Configuration::load(void)
{
FILE* in = fopen(BASEPATH.c_str(), "rt");
if (in != NULL)
{
if (in != NULL) {
mJson = nlohmann::json::parse(in, nullptr, false);
fclose(in);
}
@ -212,26 +201,22 @@ void Configuration::parse(void)
// parse filters
std::vector<std::string> filter = mJson["filter"];
for (auto& id : filter)
{
for (auto& id : filter) {
mFilterIds.emplace(strtoull(id.c_str(), NULL, 16));
}
// parse favorites
std::vector<std::string> favorites = mJson["favorites"];
for (auto& id : favorites)
{
for (auto& id : favorites) {
mFavoriteIds.emplace(strtoull(id.c_str(), NULL, 16));
}
// parse additional save folders
auto js = mJson["additional_save_folders"];
for (auto it = js.begin(); it != js.end(); ++it)
{
for (auto it = js.begin(); it != js.end(); ++it) {
std::vector<std::string> folders = it.value()["folders"];
std::vector<std::string> sfolders;
for (auto& folder : folders)
{
for (auto& folder : folders) {
sfolders.push_back(folder);
}
mAdditionalSaveFolders.emplace(strtoull(it.key().c_str(), NULL, 16), sfolders);

View file

@ -1,55 +1,52 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "directory.hpp"
Directory::Directory(const std::string& root)
{
mGood = false;
mGood = false;
mError = 0;
mList.clear();
DIR* dir = opendir(root.c_str());
struct dirent* ent;
if (dir == NULL)
{
if (dir == NULL) {
mError = (Result)errno;
}
else
{
while ((ent = readdir(dir)))
{
std::string name = std::string(ent->d_name);
bool directory = ent->d_type == DT_DIR;
struct DirectoryEntry de = { name, directory };
else {
while ((ent = readdir(dir))) {
std::string name = std::string(ent->d_name);
bool directory = ent->d_type == DT_DIR;
struct DirectoryEntry de = {name, directory};
mList.push_back(de);
}
}
closedir(dir);
mGood = true;
}
@ -71,7 +68,7 @@ std::string Directory::entry(size_t index)
bool Directory::folder(size_t index)
{
return index < mList.size() ? mList.at(index).directory : false;
return index < mList.size() ? mList.at(index).directory : false;
}
size_t Directory::size(void)

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "filesystem.hpp"

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "gui.hpp"
@ -31,9 +31,9 @@ static Clickable* buttonRestore;
static Clickable* buttonCheats;
static Scrollable* backupList;
static const size_t rowlen = 5;
static const size_t collen = 4;
static const size_t rows = 10;
static const size_t rowlen = 5;
static const size_t collen = 4;
static const size_t rows = 10;
static const size_t SIDEBAR_w = 96;
static HidHorizontal* hid;
static entryType_t type;
@ -63,12 +63,10 @@ std::string Gui::nameFromCell(size_t index)
void Gui::resetIndex(entryType_t type)
{
if (type == TITLES)
{
if (type == TITLES) {
hid->reset();
}
else
{
else {
backupList->resetIndex();
}
}
@ -80,23 +78,21 @@ size_t Gui::index(entryType_t type)
void Gui::index(entryType_t type, size_t i)
{
if (type == TITLES)
{
if (type == TITLES) {
hid->page(i / hid->maxVisibleEntries());
hid->index(i - hid->page() * hid->maxVisibleEntries());
}
else
{
else {
backupList->setIndex(i);
}
}
static void drawOutline(u32 x, u32 y, u16 w, u16 h, u8 size, SDL_Color color)
{
SDLH_DrawRect(x - size, y - size, w + 2*size, size, color); // top
SDLH_DrawRect(x - size, y, size, h, color); // left
SDLH_DrawRect(x + w, y, size, h, color); // right
SDLH_DrawRect(x - size, y + h, w + 2*size, size, color); // bottom
SDLH_DrawRect(x - size, y - size, w + 2 * size, size, color); // top
SDLH_DrawRect(x - size, y, size, h, color); // left
SDLH_DrawRect(x + w, y, size, h, color); // right
SDLH_DrawRect(x - size, y + h, w + 2 * size, size, color); // bottom
}
void Gui::drawCopy(const std::string& src, u64 offset, u64 size)
@ -115,36 +111,31 @@ void Gui::drawCopy(const std::string& src, u64 offset, u64 size)
bool Gui::askForConfirmation(const std::string& text)
{
bool ret = false;
bool ret = false;
Clickable* buttonYes = new Clickable(322, 462, 316, 56, theme().c3, theme().c6, "Yes", true);
Clickable* buttonNo = new Clickable(642, 462, 316, 56, theme().c3, theme().c6, "No", true);
HidHorizontal* hid = new HidHorizontal(2, 2);
Clickable* buttonNo = new Clickable(642, 462, 316, 56, theme().c3, theme().c6, "No", true);
HidHorizontal* hid = new HidHorizontal(2, 2);
u32 w, h;
SDLH_GetTextDimensions(28, text.c_str(), &w, &h);
while(appletMainLoop())
{
while (appletMainLoop()) {
hidScanInput();
hid->update(2);
if (buttonYes->released() ||
((hidKeysDown(CONTROLLER_P1_AUTO) & KEY_A) && hid->index() == 0))
{
if (buttonYes->released() || ((hidKeysDown(CONTROLLER_P1_AUTO) & KEY_A) && hid->index() == 0)) {
ret = true;
break;
}
else if (buttonNo->released() ||
(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_B) ||
((hidKeysDown(CONTROLLER_P1_AUTO) & KEY_A) && hid->index() == 1))
{
else if (buttonNo->released() || (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_B) ||
((hidKeysDown(CONTROLLER_P1_AUTO) & KEY_A) && hid->index() == 1)) {
break;
}
hid->index(buttonYes->held() ? 0 : buttonNo->held() ? 1 : hid->index());
buttonYes->selected(hid->index() == 0);
buttonNo->selected(hid->index() == 1);
SDLH_DrawRect(320, 200, 640, 260, theme().c3);
SDLH_DrawText(28, ceilf(1280 - w) / 2, 200 + ceilf((260 - h) / 2), theme().c6, text.c_str());
drawOutline(322, 462, 316, 56, 2, theme().c5);
@ -152,18 +143,16 @@ bool Gui::askForConfirmation(const std::string& text)
buttonYes->draw(28, COLOR_BLUE);
buttonNo->draw(28, COLOR_BLUE);
if (hid->index() == 0)
{
if (hid->index() == 0) {
drawPulsingOutline(324, 464, 312, 52, 4, COLOR_BLUE);
}
else
{
else {
drawPulsingOutline(644, 464, 312, 52, 4, COLOR_BLUE);
}
SDLH_Render();
}
delete hid;
delete buttonYes;
delete buttonNo;
@ -177,22 +166,18 @@ void Gui::showInfo(const std::string& message)
u32 w, h;
SDLH_GetTextDimensions(28, message.c_str(), &w, &h);
while(appletMainLoop())
{
while (appletMainLoop()) {
hidScanInput();
if (button->released() ||
(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_A) ||
(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_B))
{
if (button->released() || (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_A) || (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_B)) {
break;
}
SDLH_DrawRect(320, 200, 640, 260, theme().c3);
SDLH_DrawText(28, ceilf(1280 - w) / 2, 200 + ceilf((260 - h) / 2), theme().c6, message.c_str());
button->draw(28, COLOR_BLUE);
drawPulsingOutline(322, 462, 636, 56, 4, COLOR_BLUE);
SDLH_Render();
}
@ -206,23 +191,19 @@ void Gui::showError(Result res, const std::string& message)
u32 w, h;
SDLH_GetTextDimensions(28, message.c_str(), &w, &h);
while(appletMainLoop())
{
while (appletMainLoop()) {
hidScanInput();
if (button->released() ||
(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_A) ||
(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_B))
{
if (button->released() || (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_A) || (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_B)) {
break;
}
SDLH_DrawRect(320, 200, 640, 260, theme().c0);
SDLH_DrawText(20, 330, 210, COLOR_RED, StringUtils::format("Error: 0x%0llX", res).c_str());
SDLH_DrawText(28, ceilf(1280 - w) / 2, 200 + ceilf((260 - h) / 2), theme().c6, message.c_str());
button->draw(28, COLOR_RED);
drawPulsingOutline(322, 462, 636, 56, 4, COLOR_RED);
SDLH_Render();
}
@ -231,21 +212,20 @@ void Gui::showError(Result res, const std::string& message)
bool Gui::init(void)
{
if (!SDLH_Init())
{
if (!SDLH_Init()) {
return false;
}
sprintf(ver, "v%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO);
hid = new HidHorizontal(rowlen * collen, collen);
backupList = new Scrollable(538, 276, 414, 380, rows);
buttonBackup = new Clickable(956, 276, 220, 80, theme().c2, theme().c6, "Backup \ue004", true);
hid = new HidHorizontal(rowlen * collen, collen);
backupList = new Scrollable(538, 276, 414, 380, rows);
buttonBackup = new Clickable(956, 276, 220, 80, theme().c2, theme().c6, "Backup \ue004", true);
buttonRestore = new Clickable(956, 360, 220, 80, theme().c2, theme().c6, "Restore \ue005", true);
buttonCheats = new Clickable(956, 444, 220, 80, theme().c2, theme().c6, "Cheats \ue0c5", true);
buttonCheats = new Clickable(956, 444, 220, 80, theme().c2, theme().c6, "Cheats \ue0c5", true);
buttonBackup->canChangeColorWhenSelected(true);
buttonRestore->canChangeColorWhenSelected(true);
buttonCheats->canChangeColorWhenSelected(true);
return true;
}
@ -261,9 +241,9 @@ void Gui::exit(void)
void Gui::draw(void)
{
auto selEnt = MS::selectedEntries();
auto selEnt = MS::selectedEntries();
const size_t entries = hid->maxVisibleEntries();
const size_t max = hid->maxEntries(getTitleCount(g_currentUId)) + 1;
const size_t max = hid->maxEntries(getTitleCount(g_currentUId)) + 1;
SDLH_ClearScreen(theme().c1);
SDL_Color colorBar = Gui::getPKSMBridgeFlag() ? COLOR_HIGHBLUE : FC_MakeColor(theme().c1.r - 15, theme().c1.g - 15, theme().c1.b - 15, 255);
@ -272,60 +252,54 @@ void Gui::draw(void)
u32 nick_w, nick_h;
SDLH_GetTextDimensions(13, Account::username(g_currentUId).c_str(), &nick_w, &nick_h);
drawPulsingOutline(1280 - SIDEBAR_w + (SIDEBAR_w - USER_ICON_SIZE) / 2, 720 - USER_ICON_SIZE - 30, USER_ICON_SIZE, USER_ICON_SIZE, 2, COLOR_GREEN);
SDLH_DrawImageScale(Account::icon(g_currentUId), 1280 - SIDEBAR_w + (SIDEBAR_w - USER_ICON_SIZE) / 2, 720 - USER_ICON_SIZE - 30, USER_ICON_SIZE, USER_ICON_SIZE);
SDLH_DrawTextBox(13, 1280 - SIDEBAR_w + (SIDEBAR_w - nick_w) / 2, 720 - 28 + (28 - nick_h) / 2, theme().c6, SIDEBAR_w, Account::username(g_currentUId).c_str());
drawPulsingOutline(
1280 - SIDEBAR_w + (SIDEBAR_w - USER_ICON_SIZE) / 2, 720 - USER_ICON_SIZE - 30, USER_ICON_SIZE, USER_ICON_SIZE, 2, COLOR_GREEN);
SDLH_DrawImageScale(
Account::icon(g_currentUId), 1280 - SIDEBAR_w + (SIDEBAR_w - USER_ICON_SIZE) / 2, 720 - USER_ICON_SIZE - 30, USER_ICON_SIZE, USER_ICON_SIZE);
SDLH_DrawTextBox(13, 1280 - SIDEBAR_w + (SIDEBAR_w - nick_w) / 2, 720 - 28 + (28 - nick_h) / 2, theme().c6, SIDEBAR_w,
Account::username(g_currentUId).c_str());
// title icons
for (size_t k = hid->page()*entries; k < hid->page()*entries + max; k++)
{
for (size_t k = hid->page() * entries; k < hid->page() * entries + max; k++) {
int selectorx = selectorX(k);
int selectory = selectorY(k);
if (smallIcon(g_currentUId, k) != NULL)
{
if (smallIcon(g_currentUId, k) != NULL) {
SDLH_DrawImageScale(smallIcon(g_currentUId, k), selectorx, selectory, 128, 128);
}
else
{
else {
SDLH_DrawRect(selectorx, selectory, 128, 128, theme().c0);
}
if (!selEnt.empty() && std::find(selEnt.begin(), selEnt.end(), k) != selEnt.end())
{
if (!selEnt.empty() && std::find(selEnt.begin(), selEnt.end(), k) != selEnt.end()) {
SDLH_DrawIcon("checkbox", selectorx + 86, selectory + 86);
}
if (favorite(g_currentUId, k))
{
if (favorite(g_currentUId, k)) {
SDLH_DrawRect(selectorx + 94, selectory + 8, 24, 24, COLOR_GOLD);
SDLH_DrawIcon("star", selectorx + 86, selectory);
}
}
// title selector
if (getTitleCount(g_currentUId) > 0)
{
const int x = selectorX(hid->index()) + 4/2;
const int y = selectorY(hid->index()) + 4/2;
if (getTitleCount(g_currentUId) > 0) {
const int x = selectorX(hid->index()) + 4 / 2;
const int y = selectorY(hid->index()) + 4 / 2;
drawPulsingOutline(x, y, 124, 124, 4, COLOR_BLUE);
SDLH_DrawRect(x, y, 124, 124, FC_MakeColor(255, 255, 255, 80));
}
if (getTitleCount(g_currentUId) > 0)
{
if (getTitleCount(g_currentUId) > 0) {
Title title;
getTitle(title, g_currentUId, hid->fullIndex());
backupList->flush();
std::vector<std::string> dirs = title.saves();
for (size_t i = 0; i < dirs.size(); i++)
{
for (size_t i = 0; i < dirs.size(); i++) {
backupList->push_back(theme().c2, theme().c6, dirs.at(i), i == backupList->index());
}
if (title.icon() != NULL)
{
if (title.icon() != NULL) {
drawOutline(1018, 6, 256, 256, 4, theme().c3);
SDLH_DrawImage(title.icon(), 1018, 6);
}
@ -340,27 +314,27 @@ void Gui::draw(void)
SDLH_GetTextDimensions(23, "User: ", &user_w, NULL);
h += 6;
u32 offset = 10 + title_h + h/2;
int i = 0;
u32 offset = 10 + title_h + h / 2;
int i = 0;
SDLH_DrawRect(534, 2, 482, 16 + title_h, theme().c3);
SDLH_DrawRect(534, offset - h/2 - 2, 480, h*(displayName.second.length() > 0 ? 4 : 3) + h/2, theme().c2);
SDLH_DrawRect(534, offset - h / 2 - 2, 480, h * (displayName.second.length() > 0 ? 4 : 3) + h / 2, theme().c2);
SDLH_DrawText(28, 538 - 8 + 482 - title_w, 8, theme().c5, displayName.first.c_str());
if (displayName.second.length() > 0)
{
SDLH_DrawText(23, 538, offset + h*i, theme().c5, "Title:");
SDLH_DrawTextBox(23, 538 + subtitle_w, offset + h*(i++), theme().c6, 478 - 4*2 - subtitle_w, displayName.second.c_str());
if (displayName.second.length() > 0) {
SDLH_DrawText(23, 538, offset + h * i, theme().c5, "Title:");
SDLH_DrawTextBox(23, 538 + subtitle_w, offset + h * (i++), theme().c6, 478 - 4 * 2 - subtitle_w, displayName.second.c_str());
}
SDLH_DrawText(23, 538, offset + h*i, theme().c5, "Title ID:");
SDLH_DrawTextBox(23, 538 + titleid_w, offset + h*(i++), theme().c6, 478 - 4*2 - titleid_w, StringUtils::format("%016llX", title.id()).c_str());
SDLH_DrawText(23, 538, offset + h*i, theme().c5, "Author:");
SDLH_DrawTextBox(23, 538 + producer_w, offset + h*(i++), theme().c6, 478 - 4*2 - producer_w, title.author().c_str());
SDLH_DrawText(23, 538, offset + h*i, theme().c5, "User:");
SDLH_DrawTextBox(23, 538 + user_w, offset + h*(i++), theme().c6, 478 - 4*2 - user_w, title.userName().c_str());
SDLH_DrawText(23, 538, offset + h * i, theme().c5, "Title ID:");
SDLH_DrawTextBox(
23, 538 + titleid_w, offset + h * (i++), theme().c6, 478 - 4 * 2 - titleid_w, StringUtils::format("%016llX", title.id()).c_str());
SDLH_DrawText(23, 538, offset + h * i, theme().c5, "Author:");
SDLH_DrawTextBox(23, 538 + producer_w, offset + h * (i++), theme().c6, 478 - 4 * 2 - producer_w, title.author().c_str());
SDLH_DrawText(23, 538, offset + h * i, theme().c5, "User:");
SDLH_DrawTextBox(23, 538 + user_w, offset + h * (i++), theme().c6, 478 - 4 * 2 - user_w, title.userName().c_str());
drawOutline(538, 276, 414, 380, 4, theme().c3);
drawOutline(956, 276, 220, 80, 4, theme().c3);
@ -378,31 +352,28 @@ void Gui::draw(void)
SDLH_GetTextDimensions(26, "checkpoint", &checkpoint_w, &checkpoint_h);
SDLH_GetTextDimensions(24, "\ue046 Instructions", &inst_w, &inst_h);
if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_MINUS)
{
if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_MINUS) {
SDLH_DrawRect(0, 0, 1280, 720, FC_MakeColor(0, 0, 0, 190));
SDLH_DrawText(27, 1205, 646, theme().c6, "\ue085\ue086");
SDLH_DrawText(24, 58, 69, theme().c6, "\ue058 Tap to select title");
SDLH_DrawText(24, 100, 330, theme().c6, "\ue006 \ue080 to scroll between titles");
SDLH_DrawText(24, 100, 360, theme().c6, "\ue000 to enter the selected title");
SDLH_DrawText(24, 100, 390, theme().c6, "\ue001 to exit the selected title");
if (Configuration::getInstance().isPKSMBridgeEnabled())
{
if (Configuration::getInstance().isPKSMBridgeEnabled()) {
SDLH_DrawText(24, 100, 420, theme().c6, "\ue004 + \ue005 to enable PKSM bridge");
}
SDLH_DrawText(24, 616, 450, theme().c6, "\ue002 to delete a backup");
if (gethostid() != INADDR_LOOPBACK)
{
SDLH_DrawText(24, 16*6 + checkpoint_w + 8 + ver_w + inst_w, 672 + (40 - checkpoint_h) / 2 + checkpoint_h - inst_h, COLOR_GOLD,
if (gethostid() != INADDR_LOOPBACK) {
SDLH_DrawText(24, 16 * 6 + checkpoint_w + 8 + ver_w + inst_w, 672 + (40 - checkpoint_h) / 2 + checkpoint_h - inst_h, COLOR_GOLD,
StringUtils::format("Configuration server running on %s:8000", getConsoleIP()).c_str());
}
}
}
SDLH_DrawRect(0, 672, checkpoint_w + ver_w + 2*16 + 8, 40, lightBlack);
SDLH_DrawRect(0, 672, checkpoint_w + ver_w + 2 * 16 + 8, 40, lightBlack);
SDLH_DrawText(26, 16, 672 + (40 - checkpoint_h) / 2 + 2, theme().c6, "checkpoint");
SDLH_DrawText(20, 16 + checkpoint_w + 8, 672 + (40 - checkpoint_h) / 2 + checkpoint_h - ver_h, theme().c6, ver);
SDLH_DrawText(24, 16*3 + checkpoint_w + 8 + ver_w, 672 + (40 - checkpoint_h) / 2 + checkpoint_h - inst_h, theme().c6, "\ue046 Instructions");
SDLH_DrawText(24, 16 * 3 + checkpoint_w + 8 + ver_w, 672 + (40 - checkpoint_h) / 2 + checkpoint_h - inst_h, theme().c6, "\ue046 Instructions");
SDLH_Render();
}
@ -423,8 +394,7 @@ bool Gui::isCheatReleased(void)
void Gui::updateButtons(void)
{
if (MS::multipleSelectionEnabled())
{
if (MS::multipleSelectionEnabled()) {
buttonRestore->canChangeColorWhenSelected(true);
buttonRestore->canChangeColorWhenSelected(false);
buttonCheats->canChangeColorWhenSelected(false);
@ -432,8 +402,7 @@ void Gui::updateButtons(void)
buttonRestore->setColors(theme().c2, theme().c5);
buttonCheats->setColors(theme().c2, theme().c5);
}
else if (g_backupScrollEnabled)
{
else if (g_backupScrollEnabled) {
buttonBackup->canChangeColorWhenSelected(true);
buttonRestore->canChangeColorWhenSelected(true);
buttonCheats->canChangeColorWhenSelected(true);
@ -441,33 +410,28 @@ void Gui::updateButtons(void)
buttonRestore->setColors(theme().c2, theme().c6);
buttonCheats->setColors(theme().c2, theme().c6);
}
else
{
else {
buttonBackup->setColors(theme().c2, theme().c6);
buttonRestore->setColors(theme().c2, theme().c6);
buttonCheats->setColors(theme().c2, theme().c6);
}
if (getPKSMBridgeFlag())
{
if (getPKSMBridgeFlag()) {
buttonBackup->text("Send \ue004");
buttonRestore->text("Receive \ue005");
}
else
{
else {
buttonBackup->text("Backup \ue004");
buttonRestore->text("Restore \ue005");
buttonRestore->text("Restore \ue005");
}
static bool shouldCheckCheatManager = true;
if (CheatManager::loaded() && shouldCheckCheatManager)
{
if (CheatManager::loaded() && shouldCheckCheatManager) {
buttonCheats->text("Cheats \ue0c5");
buttonCheats->setColors(theme().c2, theme().c6);
shouldCheckCheatManager = false;
}
else if (!CheatManager::loaded())
{
else if (!CheatManager::loaded()) {
buttonCheats->text("Loading...");
buttonCheats->setColors(theme().c2, theme().c5);
}
@ -475,53 +439,45 @@ void Gui::updateButtons(void)
void Gui::updateSelector(void)
{
if (!g_backupScrollEnabled)
{
if (!g_backupScrollEnabled) {
size_t oldindex = hid->index();
hid->update(getTitleCount(g_currentUId));
// loop through every rendered title
touchPosition touch;
hidTouchRead(&touch, 0);
for (u8 row = 0; row < rowlen; row++)
{
for (u8 col = 0; col < collen; col++)
{
for (u8 row = 0; row < rowlen; row++) {
for (u8 col = 0; col < collen; col++) {
u8 index = row * collen + col;
if (index > hid->maxEntries(getTitleCount(g_currentUId)))
break;
u32 x = selectorX(index);
u32 y = selectorY(index);
if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH &&
touch.px >= x && touch.px <= x + 128 &&
touch.py >= y && touch.py <= y + 128)
{
if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH && touch.px >= x && touch.px <= x + 128 && touch.py >= y && touch.py <= y + 128) {
hid->index(index);
}
}
}
backupList->resetIndex();
if (hid->index() != oldindex)
{
if (hid->index() != oldindex) {
Gui::setPKSMBridgeFlag(false);
}
}
else
{
else {
backupList->updateSelection();
}
}
static int selectorX(size_t i)
{
return 128*((i % (rowlen*collen)) % collen) + 4 * (((i % (rowlen*collen)) % collen) + 1);
return 128 * ((i % (rowlen * collen)) % collen) + 4 * (((i % (rowlen * collen)) % collen) + 1);
}
static int selectorY(size_t i)
{
return 128*((i % (rowlen*collen)) / collen) + 4 * (((i % (rowlen*collen)) / collen) + 1);
return 128 * ((i % (rowlen * collen)) / collen) + 4 * (((i % (rowlen * collen)) / collen) + 1);
}
bool Gui::getPKSMBridgeFlag(void)

View file

@ -1,43 +1,42 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "io.hpp"
bool io::fileExists(const std::string& path)
{
struct stat buffer;
return (stat (path.c_str(), &buffer) == 0);
struct stat buffer;
return (stat(path.c_str(), &buffer) == 0);
}
void io::copyFile(const std::string& srcPath, const std::string& dstPath)
{
FILE* src = fopen(srcPath.c_str(), "rb");
FILE* dst = fopen(dstPath.c_str(), "wb");
if (!src || !dst)
{
if (!src || !dst) {
return;
}
@ -45,9 +44,9 @@ void io::copyFile(const std::string& srcPath, const std::string& dstPath)
u64 sz = ftell(src);
rewind(src);
u8* buf = new u8[BUFFER_SIZE];
u64 offset = 0;
size_t slashpos = srcPath.rfind("/");
u8* buf = new u8[BUFFER_SIZE];
u64 offset = 0;
size_t slashpos = srcPath.rfind("/");
std::string name = srcPath.substr(slashpos + 1, srcPath.length() - slashpos - 1);
while (offset < sz) {
u32 count = fread((char*)buf, 1, BUFFER_SIZE, src);
@ -61,8 +60,7 @@ void io::copyFile(const std::string& srcPath, const std::string& dstPath)
fclose(dst);
// commit each file to the save
if (dstPath.rfind("save:/", 0) == 0)
{
if (dstPath.rfind("save:/", 0) == 0) {
fsdevCommitDevice("save");
}
}
@ -70,39 +68,33 @@ void io::copyFile(const std::string& srcPath, const std::string& dstPath)
Result io::copyDirectory(const std::string& srcPath, const std::string& dstPath)
{
Result res = 0;
bool quit = false;
bool quit = false;
Directory items(srcPath);
if (!items.good())
{
if (!items.good()) {
return items.error();
}
for (size_t i = 0, sz = items.size(); i < sz && !quit; i++)
{
for (size_t i = 0, sz = items.size(); i < sz && !quit; i++) {
std::string newsrc = srcPath + items.entry(i);
std::string newdst = dstPath + items.entry(i);
if (items.folder(i))
{
if (items.folder(i)) {
res = io::createDirectory(newdst);
if (R_SUCCEEDED(res))
{
if (R_SUCCEEDED(res)) {
newsrc += "/";
newdst += "/";
res = io::copyDirectory(newsrc, newdst);
}
else
{
else {
quit = true;
}
}
else
{
else {
io::copyFile(newsrc, newdst);
}
}
return 0;
}
@ -121,22 +113,18 @@ bool io::directoryExists(const std::string& path)
Result io::deleteFolderRecursively(const std::string& path)
{
Directory dir(path);
if (!dir.good())
{
if (!dir.good()) {
return dir.error();
}
for (size_t i = 0, sz = dir.size(); i < sz; i++)
{
if (dir.folder(i))
{
for (size_t i = 0, sz = dir.size(); i < sz; i++) {
if (dir.folder(i)) {
std::string newpath = path + "/" + dir.entry(i) + "/";
deleteFolderRecursively(newpath);
newpath = path + dir.entry(i);
rmdir(newpath.c_str());
}
else
{
else {
std::string newpath = path + dir.entry(i);
std::remove(newpath.c_str());
}
@ -149,110 +137,95 @@ Result io::deleteFolderRecursively(const std::string& path)
void io::backup(size_t index, u128 uid)
{
// check if multiple selection is enabled and don't ask for confirmation if that's the case
if (!MS::multipleSelectionEnabled())
{
if (!Gui::askForConfirmation("Backup selected save?"))
{
if (!MS::multipleSelectionEnabled()) {
if (!Gui::askForConfirmation("Backup selected save?")) {
return;
}
}
const size_t cellIndex = Gui::index(CELLS);
const bool isNewFolder = cellIndex == 0;
Result res = 0;
Result res = 0;
Title title;
getTitle(title, uid, index);
FsFileSystem fileSystem;
res = FileSystem::mount(&fileSystem, title.id(), title.userId());
if (R_SUCCEEDED(res))
{
if (R_SUCCEEDED(res)) {
int ret = FileSystem::mount(fileSystem);
if (ret == -1)
{
if (ret == -1) {
FileSystem::unmount();
Gui::showError(-2, "Failed to mount save.");
return;
}
}
else
{
else {
Gui::showError(res, "Failed to mount save.");
return;
}
std::string suggestion = DateTime::dateTimeStr() + " " + (StringUtils::containsInvalidChar(Account::username(title.userId())) ? "" : StringUtils::removeNotAscii(StringUtils::removeAccents(Account::username(title.userId()))));
std::string suggestion = DateTime::dateTimeStr() + " " +
(StringUtils::containsInvalidChar(Account::username(title.userId()))
? ""
: StringUtils::removeNotAscii(StringUtils::removeAccents(Account::username(title.userId()))));
std::string customPath;
if (MS::multipleSelectionEnabled())
{
if (MS::multipleSelectionEnabled()) {
customPath = isNewFolder ? suggestion : "";
}
else
{
if (isNewFolder)
{
else {
if (isNewFolder) {
std::pair<bool, std::string> keyboardResponse = KeyboardManager::get().keyboard(suggestion);
if (keyboardResponse.first)
{
if (keyboardResponse.first) {
customPath = StringUtils::removeForbiddenCharacters(keyboardResponse.second);
}
else
{
else {
FileSystem::unmount();
return;
}
}
else
{
else {
customPath = "";
}
}
std::string dstPath;
if (!isNewFolder)
{
if (!isNewFolder) {
// we're overriding an existing folder
dstPath = title.fullPath(cellIndex);
}
else
{
else {
dstPath = title.path() + "/" + customPath;
}
}
if (!isNewFolder || io::directoryExists(dstPath))
{
if (!isNewFolder || io::directoryExists(dstPath)) {
int ret = io::deleteFolderRecursively((dstPath + "/").c_str());
if (ret != 0)
{
if (ret != 0) {
FileSystem::unmount();
Gui::showError((Result)ret, "Failed to delete the existing backup\ndirectory recursively.");
return;
}
}
res = io::createDirectory(dstPath);
res = io::copyDirectory("save:/", dstPath + "/");
if (R_FAILED(res))
{
if (R_FAILED(res)) {
FileSystem::unmount();
io::deleteFolderRecursively((dstPath + "/").c_str());
Gui::showError(res, "Failed to backup save.");
return;
}
refreshDirectories(title.id());
FileSystem::unmount();
if (!MS::multipleSelectionEnabled())
{
if (!MS::multipleSelectionEnabled()) {
blinkLed(4);
Gui::showInfo("Progress correctly saved to disk.");
}
auto systemKeyboardAvailable = KeyboardManager::get().isSystemKeyboardAvailable();
if (!systemKeyboardAvailable.first)
{
if (!systemKeyboardAvailable.first) {
Gui::showError(systemKeyboardAvailable.second, "System keyboard applet not accessible.\nThe suggested destination folder was used\ninstead.");
}
}
@ -260,63 +233,55 @@ void io::backup(size_t index, u128 uid)
void io::restore(size_t index, u128 uid)
{
const size_t cellIndex = Gui::index(CELLS);
if (cellIndex == 0 || !Gui::askForConfirmation("Restore selected save?"))
{
if (cellIndex == 0 || !Gui::askForConfirmation("Restore selected save?")) {
return;
}
Result res = 0;
Title title;
getTitle(title, uid, index);
FsFileSystem fileSystem;
res = title.systemSave() ? FileSystem::mount(&fileSystem, title.id()) : FileSystem::mount(&fileSystem, title.id(), title.userId());
if (R_SUCCEEDED(res))
{
if (R_SUCCEEDED(res)) {
int ret = FileSystem::mount(fileSystem);
if (ret == -1)
{
if (ret == -1) {
FileSystem::unmount();
Gui::showError(-2, "Failed to mount save.");
return;
}
}
else
{
else {
Gui::showError(res, "Failed to mount save.");
return;
return;
}
std::string srcPath = title.fullPath(cellIndex) + "/";
std::string dstPath = "save:/";
res = io::deleteFolderRecursively(dstPath.c_str());
if (R_FAILED(res))
{
if (R_FAILED(res)) {
FileSystem::unmount();
Gui::showError(res, "Failed to delete save.");
return;
}
res = io::copyDirectory(srcPath, dstPath);
if (R_FAILED(res))
{
if (R_FAILED(res)) {
FileSystem::unmount();
Gui::showError(res, "Failed to restore save.");
return;
}
res = fsdevCommitDevice("save");
if (R_FAILED(res))
{
if (R_FAILED(res)) {
Gui::showError(res, "Failed to commit to save device.");
}
else
{
else {
blinkLed(4);
Gui::showInfo(Gui::nameFromCell(cellIndex) + "\nhas been restored successfully.");
}
FileSystem::unmount();
}

View file

@ -1,39 +1,38 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "main.hpp"
u128 g_currentUId = 0;
u128 g_currentUId = 0;
bool g_backupScrollEnabled = 0;
int main(int argc, char** argv)
{
Result res = servicesInit();
if (R_FAILED(res))
{
if (R_FAILED(res)) {
servicesExit();
return res;
}
@ -42,30 +41,27 @@ int main(int argc, char** argv)
// get the user IDs
std::vector<u128> userIds = Account::ids();
// set g_currentUId to a default user in case we loaded at least one user
if (g_currentUId == 0) g_currentUId = userIds.at(0);
if (g_currentUId == 0)
g_currentUId = userIds.at(0);
int selectionTimer = 0;
while(appletMainLoop() && !(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_PLUS))
{
while (appletMainLoop() && !(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_PLUS)) {
hidScanInput();
u32 kdown = hidKeysDown(CONTROLLER_P1_AUTO);
u32 kheld = hidKeysHeld(CONTROLLER_P1_AUTO);
if (kdown & KEY_ZL || kdown & KEY_ZR)
{
while((g_currentUId = Account::selectAccount()) == 0);
if (kdown & KEY_ZL || kdown & KEY_ZR) {
while ((g_currentUId = Account::selectAccount()) == 0)
;
Gui::index(TITLES, 0);
Gui::index(CELLS, 0);
Gui::setPKSMBridgeFlag(false);
}
// handle PKSM bridge
if (Configuration::getInstance().isPKSMBridgeEnabled())
{
if (Configuration::getInstance().isPKSMBridgeEnabled()) {
Title title;
getTitle(title, g_currentUId, Gui::index(TITLES));
if (!Gui::getPKSMBridgeFlag())
{
if ((kheld & KEY_L) && (kheld & KEY_R) && isPKSMBridgeTitle(title.id()))
{
if (!Gui::getPKSMBridgeFlag()) {
if ((kheld & KEY_L) && (kheld & KEY_R) && isPKSMBridgeTitle(title.id())) {
Gui::setPKSMBridgeFlag(true);
Gui::updateButtons();
}
@ -75,27 +71,20 @@ int main(int argc, char** argv)
// handle touchscreen
touchPosition touch;
hidTouchRead(&touch, 0);
if (!g_backupScrollEnabled &&
hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH &&
touch.px >= 1200 && touch.px <= 1200 + USER_ICON_SIZE &&
touch.py >= 626 && touch.py <= 626 + USER_ICON_SIZE)
{
while ((g_currentUId = Account::selectAccount()) == 0);
if (!g_backupScrollEnabled && hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH && touch.px >= 1200 && touch.px <= 1200 + USER_ICON_SIZE &&
touch.py >= 626 && touch.py <= 626 + USER_ICON_SIZE) {
while ((g_currentUId = Account::selectAccount()) == 0)
;
Gui::index(TITLES, 0);
Gui::index(CELLS, 0);
Gui::setPKSMBridgeFlag(false);
}
// Handle touching the backup list
if ((hidKeysDown(CONTROLLER_P1_AUTO) & KEY_TOUCH &&
(int)touch.px > 538 &&
(int)touch.px < 952 &&
(int)touch.py > 276 &&
(int)touch.py < 656))
{
if ((hidKeysDown(CONTROLLER_P1_AUTO) & KEY_TOUCH && (int)touch.px > 538 && (int)touch.px < 952 && (int)touch.py > 276 &&
(int)touch.py < 656)) {
// Activate backup list only if multiple selections are enabled
if (!MS::multipleSelectionEnabled())
{
if (!MS::multipleSelectionEnabled()) {
g_backupScrollEnabled = true;
Gui::updateButtons();
Gui::entryType(CELLS);
@ -106,36 +95,27 @@ int main(int argc, char** argv)
// Backup list active: Backup/Restore
// Backup list inactive: Activate backup list only if multiple
// selections are enabled
if (kdown & KEY_A)
{
if (kdown & KEY_A) {
// If backup list is active...
if (g_backupScrollEnabled)
{
if (g_backupScrollEnabled) {
// If the "New..." entry is selected...
if (0 == Gui::index(CELLS))
{
if (!Gui::getPKSMBridgeFlag())
{
if (0 == Gui::index(CELLS)) {
if (!Gui::getPKSMBridgeFlag()) {
io::backup(Gui::index(TITLES), g_currentUId);
}
}
else
{
if (Gui::getPKSMBridgeFlag())
{
else {
if (Gui::getPKSMBridgeFlag()) {
recvFromPKSMBridge(Gui::index(TITLES), g_currentUId);
}
else
{
else {
io::restore(Gui::index(TITLES), g_currentUId);
}
}
}
else
{
else {
// Activate backup list only if multiple selections are not enabled
if (!MS::multipleSelectionEnabled())
{
if (!MS::multipleSelectionEnabled()) {
g_backupScrollEnabled = true;
Gui::updateButtons();
Gui::entryType(CELLS);
@ -144,13 +124,8 @@ int main(int argc, char** argv)
}
// Handle pressing B
if (kdown & KEY_B ||
(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_TOUCH &&
(int)touch.px >= 0 &&
(int)touch.px <= 532 &&
(int)touch.py >= 0 &&
(int)touch.py <= 664))
{
if (kdown & KEY_B || (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_TOUCH && (int)touch.px >= 0 && (int)touch.px <= 532 && (int)touch.py >= 0 &&
(int)touch.py <= 664)) {
Gui::index(CELLS, 0);
g_backupScrollEnabled = false;
Gui::entryType(TITLES);
@ -160,13 +135,10 @@ int main(int argc, char** argv)
}
// Handle pressing X
if (kdown & KEY_X)
{
if (g_backupScrollEnabled)
{
if (kdown & KEY_X) {
if (g_backupScrollEnabled) {
size_t index = Gui::index(CELLS);
if (index > 0 && Gui::askForConfirmation("Delete selected backup?"))
{
if (index > 0 && Gui::askForConfirmation("Delete selected backup?")) {
Title title;
getTitle(title, g_currentUId, Gui::index(TITLES));
std::string path = title.fullPath(index);
@ -181,10 +153,8 @@ int main(int argc, char** argv)
// Backup list active: Deactivate backup list, select title, and
// enable backup button
// Backup list inactive: Select title and enable backup button
if (kdown & KEY_Y)
{
if (g_backupScrollEnabled)
{
if (kdown & KEY_Y) {
if (g_backupScrollEnabled) {
Gui::index(CELLS, 0);
g_backupScrollEnabled = false;
}
@ -195,34 +165,27 @@ int main(int argc, char** argv)
}
// Handle holding Y
if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_Y && !(g_backupScrollEnabled))
{
if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_Y && !(g_backupScrollEnabled)) {
selectionTimer++;
}
else
{
else {
selectionTimer = 0;
}
if (selectionTimer > 45)
{
if (selectionTimer > 45) {
MS::clearSelectedEntries();
for (size_t i = 0, sz = getTitleCount(g_currentUId); i < sz; i++)
{
for (size_t i = 0, sz = getTitleCount(g_currentUId); i < sz; i++) {
MS::addSelectedEntry(i);
}
selectionTimer = 0;
}
// Handle pressing/touching L
if (Gui::isBackupReleased() || (kdown & KEY_L))
{
if (MS::multipleSelectionEnabled())
{
if (Gui::isBackupReleased() || (kdown & KEY_L)) {
if (MS::multipleSelectionEnabled()) {
Gui::resetIndex(CELLS);
std::vector<size_t> list = MS::selectedEntries();
for (size_t i = 0, sz = list.size(); i < sz; i++)
{
for (size_t i = 0, sz = list.size(); i < sz; i++) {
io::backup(list.at(i), g_currentUId);
}
MS::clearSelectedEntries();
@ -230,55 +193,43 @@ int main(int argc, char** argv)
blinkLed(4);
Gui::showInfo("Progress correctly saved to disk.");
}
else if (g_backupScrollEnabled)
{
if (Gui::getPKSMBridgeFlag())
{
else if (g_backupScrollEnabled) {
if (Gui::getPKSMBridgeFlag()) {
sendToPKSMBrigde(Gui::index(TITLES), g_currentUId);
}
else
{
else {
io::backup(Gui::index(TITLES), g_currentUId);
}
}
}
// Handle pressing/touching R
if (Gui::isRestoreReleased() || (kdown & KEY_R))
{
if (g_backupScrollEnabled)
{
if (Gui::getPKSMBridgeFlag())
{
if (Gui::isRestoreReleased() || (kdown & KEY_R)) {
if (g_backupScrollEnabled) {
if (Gui::getPKSMBridgeFlag()) {
recvFromPKSMBridge(Gui::index(TITLES), g_currentUId);
}
else
{
else {
io::restore(Gui::index(TITLES), g_currentUId);
}
}
}
if ((Gui::isCheatReleased() || (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_RSTICK)) && CheatManager::loaded())
{
if (MS::multipleSelectionEnabled())
{
if ((Gui::isCheatReleased() || (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_RSTICK)) && CheatManager::loaded()) {
if (MS::multipleSelectionEnabled()) {
MS::clearSelectedEntries();
Gui::updateButtons();
}
else
{
else {
Title title;
getTitle(title, g_currentUId, Gui::index(TITLES));
std::string key = StringUtils::format("%016llX", title.id());
if (CheatManager::availableCodes(key))
{
if (CheatManager::availableCodes(key)) {
CheatManager::manageCheats(key);
}
else
{
else {
Gui::showInfo("No available cheat codes for this title.");
}
}
}
}

View file

@ -1,34 +1,34 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "pksmbridge.hpp"
bool isPKSMBridgeTitle(u64 id) {
if (id == 0x0100187003A36000 || id == 0x010003F003A34000)
{
bool isPKSMBridgeTitle(u64 id)
{
if (id == 0x0100187003A36000 || id == 0x010003F003A34000) {
return true;
}
return false;
@ -43,14 +43,12 @@ bool validateIpAddress(const std::string& ip)
void sendToPKSMBrigde(size_t index, u128 uid)
{
const size_t cellIndex = Gui::index(CELLS);
if (cellIndex == 0 || !Gui::askForConfirmation("Send save to PKSM?"))
{
if (cellIndex == 0 || !Gui::askForConfirmation("Send save to PKSM?")) {
return;
}
auto systemKeyboardAvailable = KeyboardManager::get().isSystemKeyboardAvailable();
if (!systemKeyboardAvailable.first)
{
if (!systemKeyboardAvailable.first) {
Gui::showError(systemKeyboardAvailable.second, "System keyboard not accessible.");
}
@ -58,9 +56,8 @@ void sendToPKSMBrigde(size_t index, u128 uid)
Title title;
getTitle(title, uid, index);
std::string srcPath = title.fullPath(cellIndex) + "/savedata.bin";
FILE* save = fopen(srcPath.c_str(), "rb");
if (save == NULL)
{
FILE* save = fopen(srcPath.c_str(), "rb");
if (save == NULL) {
return;
}
@ -73,8 +70,7 @@ void sendToPKSMBrigde(size_t index, u128 uid)
// get server address
auto ipaddress = KeyboardManager::get().keyboard("Input PKSM IP address");
if (!ipaddress.first || !validateIpAddress(ipaddress.second))
{
if (!ipaddress.first || !validateIpAddress(ipaddress.second)) {
Gui::showError(-1, "Invalid IP address.");
delete[] data;
return;
@ -83,19 +79,17 @@ void sendToPKSMBrigde(size_t index, u128 uid)
// send via TCP
int fd;
struct sockaddr_in servaddr;
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
{
if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
Gui::showError(errno, "Socket creation failed.");
delete[] data;
return;
}
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PKSM_PORT);
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PKSM_PORT);
servaddr.sin_addr.s_addr = inet_addr(ipaddress.second.c_str());
if (connect(fd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0)
{
if (connect(fd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0) {
Gui::showError(errno, "Socket connection failed.");
close(fd);
delete[] data;
@ -107,17 +101,17 @@ void sendToPKSMBrigde(size_t index, u128 uid)
int n;
while (total < size) {
size_t tosend = size - total > chunk ? chunk : size - total;
n = send(fd, data + total, tosend, 0);
if (n == -1) { break; }
n = send(fd, data + total, tosend, 0);
if (n == -1) {
break;
}
total += n;
fprintf(stderr, "Sent %lu bytes, %lu still missing\n", total, size - total);
}
if (total == size)
{
if (total == size) {
Gui::showInfo("Data sent correctly.");
}
else
{
else {
Gui::showError(errno, "Failed to send data.");
}
@ -128,32 +122,28 @@ void sendToPKSMBrigde(size_t index, u128 uid)
void recvFromPKSMBridge(size_t index, u128 uid)
{
const size_t cellIndex = Gui::index(CELLS);
if (cellIndex == 0 || !Gui::askForConfirmation("Receive save from PKSM?"))
{
if (cellIndex == 0 || !Gui::askForConfirmation("Receive save from PKSM?")) {
return;
}
int fd;
struct sockaddr_in servaddr;
if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) < 0)
{
if ((fd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP)) < 0) {
Gui::showError(errno, "Socket creation failed.");
return;
}
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PKSM_PORT);
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(PKSM_PORT);
servaddr.sin_addr.s_addr = INADDR_ANY;
if (bind(fd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0)
{
if (bind(fd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0) {
Gui::showError(errno, "Socket bind failed.");
close(fd);
return;
}
if (listen(fd, 5) < 0)
{
if (listen(fd, 5) < 0) {
Gui::showError(errno, "Socket listen failed.");
close(fd);
return;
@ -161,8 +151,7 @@ void recvFromPKSMBridge(size_t index, u128 uid)
int fdconn;
int addrlen = sizeof(servaddr);
if ((fdconn = accept(fd, (struct sockaddr*)&servaddr, (socklen_t*)&addrlen)) < 0)
{
if ((fdconn = accept(fd, (struct sockaddr*)&servaddr, (socklen_t*)&addrlen)) < 0) {
Gui::showError(errno, "Socket accept failed.");
close(fd);
return;
@ -172,9 +161,8 @@ void recvFromPKSMBridge(size_t index, u128 uid)
Title title;
getTitle(title, uid, index);
std::string srcPath = title.fullPath(cellIndex) + "/savedata.bin";
FILE* save = fopen(srcPath.c_str(), "wb");
if (save == NULL)
{
FILE* save = fopen(srcPath.c_str(), "wb");
if (save == NULL) {
return;
}
@ -185,21 +173,21 @@ void recvFromPKSMBridge(size_t index, u128 uid)
int n;
while (total < size) {
size_t torecv = size - total > chunk ? chunk : size - total;
n = recv(fdconn, data + total, torecv, 0);
if (n == -1) { break; }
n = recv(fdconn, data + total, torecv, 0);
if (n == -1) {
break;
}
total += n;
fprintf(stderr, "Recv %lu bytes, %lu still missing\n", total, size - total);
}
if (total == size)
{
if (total == size) {
Gui::showInfo("Data received correctly.");
fwrite(data, 1, size, save);
}
else
{
else {
Gui::showError(errno, "Failed to receive data.");
}
fclose(save);
close(fd);
close(fdconn);

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "scrollable.hpp"
@ -47,7 +47,7 @@ void Scrollable::resetIndex(void)
void Scrollable::push_back(SDL_Color color, SDL_Color colorMessage, const std::string& message, bool selected)
{
const float spacing = mh / mVisibleEntries;
Clickable* cell = new Clickable(mx, my + (size() % mVisibleEntries)*spacing, mw, spacing, color, colorMessage, message, false);
Clickable* cell = new Clickable(mx, my + (size() % mVisibleEntries) * spacing, mw, spacing, color, colorMessage, message, false);
cell->selected(selected);
mCells.push_back(cell);
}
@ -58,34 +58,31 @@ void Scrollable::updateSelection(void)
hidTouchRead(&touch, 0);
const int hu = (mHid->maxEntries(size()) + 1) * mh / mVisibleEntries;
if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH && touch.py > (float)my && touch.py < (float)(my+hu) && touch.px > (float)mx && touch.px < (float)(mx+mw))
{
mHid->index(ceilf((touch.py - my)*mVisibleEntries/mh));
if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH && touch.py > (float)my && touch.py < (float)(my + hu) && touch.px > (float)mx &&
touch.px < (float)(mx + mw)) {
mHid->index(ceilf((touch.py - my) * mVisibleEntries / mh));
}
mHid->update(size());
mIndex = mHid->index();
mPage = mHid->page();
mPage = mHid->page();
}
void Scrollable::draw(bool condition)
{
const size_t baseIndex = mVisibleEntries*mPage;
const size_t sz = size() - baseIndex > mVisibleEntries ? mVisibleEntries : size() - baseIndex;
for (size_t i = baseIndex; i < baseIndex + sz; i++)
{
const size_t baseIndex = mVisibleEntries * mPage;
const size_t sz = size() - baseIndex > mVisibleEntries ? mVisibleEntries : size() - baseIndex;
for (size_t i = baseIndex; i < baseIndex + sz; i++) {
mCells.at(i)->draw(20, g_backupScrollEnabled ? COLOR_BLUE : theme().c0);
}
size_t blankRows = mVisibleEntries - sz;
size_t rowHeight = mh / mVisibleEntries;
SDLH_DrawRect(mx, my + sz * rowHeight, mw, rowHeight * blankRows, theme().c2);
// draw selector
for (size_t i = baseIndex; i < baseIndex + sz; i++)
{
if (mCells.at(i)->selected())
{
for (size_t i = baseIndex; i < baseIndex + sz; i++) {
if (mCells.at(i)->selected()) {
mCells.at(i)->drawOutline(condition ? COLOR_BLUE : theme().c5);
break;
}

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "title.hpp"
@ -31,8 +31,7 @@ static std::unordered_map<u64, SDL_Texture*> icons;
void freeIcons(void)
{
for (auto& i : icons)
{
for (auto& i : icons) {
SDL_DestroyTexture(i.second);
}
}
@ -40,8 +39,7 @@ void freeIcons(void)
static void loadIcon(u64 id, NsApplicationControlData* nsacd, size_t iconsize)
{
auto it = icons.find(id);
if (it == icons.end())
{
if (it == icons.end()) {
SDL_Texture* texture;
SDLH_LoadImage(&texture, nsacd->icon, iconsize);
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_NONE);
@ -51,17 +49,16 @@ static void loadIcon(u64 id, NsApplicationControlData* nsacd, size_t iconsize)
void Title::init(u8 saveDataType, u64 id, u128 userID, const std::string& name, const std::string& author)
{
mId = id;
mUserId = userID;
mId = id;
mUserId = userID;
mSaveDataType = saveDataType;
mUserName = Account::username(userID);
mAuthor = author;
mName = name;
mSafeName = StringUtils::containsInvalidChar(name) ? StringUtils::format("0x%016llX", mId) : StringUtils::removeForbiddenCharacters(name);
mPath = "sdmc:/switch/Checkpoint/saves/" + StringUtils::format("0x%016llX", mId) + " " + mSafeName;
mUserName = Account::username(userID);
mAuthor = author;
mName = name;
mSafeName = StringUtils::containsInvalidChar(name) ? StringUtils::format("0x%016llX", mId) : StringUtils::removeForbiddenCharacters(name);
mPath = "sdmc:/switch/Checkpoint/saves/" + StringUtils::format("0x%016llX", mId) + " " + mSafeName;
if (!io::directoryExists(mPath))
{
if (!io::directoryExists(mPath)) {
io::createDirectory(mPath);
}
@ -115,16 +112,15 @@ std::string Title::name(void)
std::pair<std::string, std::string> Title::displayName(void)
{
std::string name = StringUtils::removeAccents(mName);
std::string name = StringUtils::removeAccents(mName);
std::pair<std::string, std::string> p = std::make_pair(name, "");
size_t pos = name.rfind(":");
if (pos != std::string::npos)
{
size_t pos = name.rfind(":");
if (pos != std::string::npos) {
std::string name1 = name.substr(0, pos);
std::string name2 = name.substr(pos+1);
std::string name2 = name.substr(pos + 1);
StringUtils::trim(name1);
StringUtils::trim(name2);
p.first = name1;
p.first = name1;
p.second = name2;
}
return p;
@ -157,39 +153,31 @@ void Title::refreshDirectories(void)
mFullSavePaths.clear();
Directory savelist(mPath);
if (savelist.good())
{
for (size_t i = 0, sz = savelist.size(); i < sz; i++)
{
if (savelist.folder(i))
{
if (savelist.good()) {
for (size_t i = 0, sz = savelist.size(); i < sz; i++) {
if (savelist.folder(i)) {
mSaves.push_back(savelist.entry(i));
mFullSavePaths.push_back(mPath + "/" + savelist.entry(i));
}
}
std::sort(mSaves.rbegin(), mSaves.rend());
std::sort(mFullSavePaths.rbegin(), mFullSavePaths.rend());
mSaves.insert(mSaves.begin(), "New...");
mFullSavePaths.insert(mFullSavePaths.begin(), "New...");
}
else
{
else {
Gui::showError(savelist.error(), "Couldn't retrieve the directory list for the title " + name() + ".");
}
// save backups from configuration
std::vector<std::string> additionalFolders = Configuration::getInstance().additionalSaveFolders(mId);
for (std::vector<std::string>::const_iterator it = additionalFolders.begin(); it != additionalFolders.end(); it++)
{
for (std::vector<std::string>::const_iterator it = additionalFolders.begin(); it != additionalFolders.end(); it++) {
// we have other folders to parse
Directory list(*it);
if (list.good())
{
for (size_t i = 0, sz = list.size(); i < sz; i++)
{
if (list.folder(i))
{
if (list.good()) {
for (size_t i = 0, sz = list.size(); i < sz; i++) {
if (list.folder(i)) {
mSaves.push_back(list.entry(i));
mFullSavePaths.push_back(*it + "/" + list.entry(i));
}
@ -205,44 +193,36 @@ void loadTitles(void)
FsSaveDataIterator iterator;
FsSaveDataInfo info;
size_t total_entries = 0;
size_t outsize = 0;
size_t outsize = 0;
NacpLanguageEntry* nle = NULL;
NacpLanguageEntry* nle = NULL;
NsApplicationControlData* nsacd = (NsApplicationControlData*)malloc(sizeof(NsApplicationControlData));
if (nsacd == NULL)
{
if (nsacd == NULL) {
return;
}
memset(nsacd, 0, sizeof(NsApplicationControlData));
Result res = fsOpenSaveDataIterator(&iterator, FsSaveDataSpaceId_NandUser);
if (R_FAILED(res))
{
if (R_FAILED(res)) {
free(nsacd);
return;
}
while(1)
{
while (1) {
res = fsSaveDataIteratorRead(&iterator, &info, 1, &total_entries);
if (R_FAILED(res) || total_entries == 0)
{
if (R_FAILED(res) || total_entries == 0) {
break;
}
if (info.SaveDataType == FsSaveDataType_SaveData)
{
u64 tid = info.titleID;
u64 sid = info.saveID;
if (info.SaveDataType == FsSaveDataType_SaveData) {
u64 tid = info.titleID;
u64 sid = info.saveID;
u128 uid = info.userID;
if (!Configuration::getInstance().filter(tid))
{
if (!Configuration::getInstance().filter(tid)) {
res = nsGetApplicationControlData(1, tid, nsacd, sizeof(NsApplicationControlData), &outsize);
if (R_SUCCEEDED(res) && !(outsize < sizeof(nsacd->nacp)))
{
if (R_SUCCEEDED(res) && !(outsize < sizeof(nsacd->nacp))) {
res = nacpGetLanguageEntry(&nsacd->nacp, &nle);
if (R_SUCCEEDED(res) && nle != NULL)
{
if (R_SUCCEEDED(res) && nle != NULL) {
Title title;
title.init(info.SaveDataType, tid, uid, std::string(nle->name), std::string(nle->author));
title.saveId(sid);
@ -250,13 +230,11 @@ void loadTitles(void)
// check if the vector is already created
std::unordered_map<u128, std::vector<Title>>::iterator it = titles.find(uid);
if (it != titles.end())
{
if (it != titles.end()) {
// found
it->second.push_back(title);
}
else
{
else {
// not found, insert into map
std::vector<Title> v;
v.push_back(title);
@ -272,20 +250,17 @@ void loadTitles(void)
free(nsacd);
fsSaveDataIteratorClose(&iterator);
for (auto& vect : titles)
{
for (auto& vect : titles) {
std::sort(vect.second.begin(), vect.second.end(), [](Title& l, Title& r) {
return l.name() < r.name() &&
Configuration::getInstance().favorite(l.id()) > Configuration::getInstance().favorite(r.id());
return l.name() < r.name() && Configuration::getInstance().favorite(l.id()) > Configuration::getInstance().favorite(r.id());
});
}
}
void getTitle(Title &dst, u128 uid, size_t i)
void getTitle(Title& dst, u128 uid, size_t i)
{
std::unordered_map<u128, std::vector<Title>>::iterator it = titles.find(uid);
if (it != titles.end() && i < getTitleCount(uid))
{
if (it != titles.end() && i < getTitleCount(uid)) {
dst = it->second.at(i);
}
}
@ -304,12 +279,9 @@ bool favorite(u128 uid, int i)
void refreshDirectories(u64 id)
{
for (auto& pair : titles)
{
for (size_t i = 0; i < pair.second.size(); i++)
{
if (pair.second.at(i).id() == id)
{
for (auto& pair : titles) {
for (size_t i = 0; i < pair.second.size(); i++) {
if (pair.second.at(i).id() == id) {
pair.second.at(i).refreshDirectories();
}
}
@ -319,17 +291,15 @@ void refreshDirectories(u64 id)
SDL_Texture* smallIcon(u128 uid, size_t i)
{
std::unordered_map<u128, std::vector<Title>>::iterator it = titles.find(uid);
return it != titles.end() ? it->second.at(i).icon() : NULL;
return it != titles.end() ? it->second.at(i).icon() : NULL;
}
std::unordered_map<std::string, std::string> getCompleteTitleList(void)
{
std::unordered_map<std::string, std::string> map;
for (const auto& pair : titles)
{
for (auto value : pair.second)
{
map.insert({ StringUtils::format("0x%016llX", value.id()), value.name() });
for (const auto& pair : titles) {
for (auto value : pair.second) {
map.insert({StringUtils::format("0x%016llX", value.id()), value.name()});
}
}
return map;

View file

@ -1,28 +1,28 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
* * Requiring preservation of specified reasonable legal notices or
* author attributions in that material or in the Appropriate Legal
* Notices displayed by works containing it.
* * Prohibiting misrepresentation of the origin of that material,
* or requiring that modified versions of such material be marked in
* reasonable ways as different from the original version.
*/
#include "util.hpp"
@ -31,13 +31,12 @@ bool g_notificationLedAvailable = false;
void servicesExit(void)
{
CheatManager::exit();
// debug
socketExit();
freeIcons();
if (g_notificationLedAvailable)
{
if (g_notificationLedAvailable) {
hidsysExit();
}
nsExit();
@ -50,9 +49,8 @@ void servicesExit(void)
Result servicesInit(void)
{
// debug
if (socketInitializeDefault() == 0)
{
//nxlinkStdio();
if (socketInitializeDefault() == 0) {
// nxlinkStdio();
}
Result res = 0;
@ -62,30 +60,25 @@ Result servicesInit(void)
io::createDirectory("sdmc:/switch/Checkpoint/saves");
io::createDirectory("sdmc:/switch/Checkpoint/cheats");
if (R_FAILED(res = plInitialize()))
{
if (R_FAILED(res = plInitialize())) {
return res;
}
if (R_FAILED(res = Account::init()))
{
if (R_FAILED(res = Account::init())) {
return res;
}
if (R_FAILED(res = nsInitialize()))
{
if (R_FAILED(res = nsInitialize())) {
return res;
}
if (!Gui::init())
{
}
if (!Gui::init()) {
return -1;
}
if (R_SUCCEEDED(res = hidsysInitialize()))
{
if (R_SUCCEEDED(res = hidsysInitialize())) {
g_notificationLedAvailable = true;
}
}
CheatManager::init();
@ -97,7 +90,7 @@ Result servicesInit(void)
std::u16string StringUtils::UTF8toUTF16(const char* src)
{
char16_t tmp[256] = {0};
utf8_to_utf16((uint16_t *)tmp, (uint8_t *)src, 256);
utf8_to_utf16((uint16_t*)tmp, (uint8_t*)src, 256);
return std::u16string(tmp);
}
@ -106,13 +99,11 @@ std::string StringUtils::removeAccents(std::string str)
{
std::u16string src = UTF8toUTF16(str.c_str());
const std::u16string illegal = UTF8toUTF16("ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ");
const std::u16string fixed = UTF8toUTF16("AAAAAAECEEEEIIIIDNOOOOOx0UUUUYPsaaaaaaeceeeeiiiiOnooooo/0uuuuypy");
for (size_t i = 0, sz = src.length(); i < sz; i++)
{
const std::u16string fixed = UTF8toUTF16("AAAAAAECEEEEIIIIDNOOOOOx0UUUUYPsaaaaaaeceeeeiiiiOnooooo/0uuuuypy");
for (size_t i = 0, sz = src.length(); i < sz; i++) {
size_t index = illegal.find(src[i]);
if (index != std::string::npos)
{
if (index != std::string::npos) {
src[i] = fixed[index];
}
}
@ -122,14 +113,12 @@ std::string StringUtils::removeAccents(std::string str)
std::string StringUtils::removeNotAscii(std::string str)
{
for (size_t i = 0, sz = str.length(); i < sz; i++)
{
if (!isascii(str[i]))
{
for (size_t i = 0, sz = str.length(); i < sz; i++) {
if (!isascii(str[i])) {
str[i] = ' ';
}
}
return str;
return str;
}
HidsysNotificationLedPattern blinkLedPattern(u8 times)
@ -137,34 +126,31 @@ HidsysNotificationLedPattern blinkLedPattern(u8 times)
HidsysNotificationLedPattern pattern;
memset(&pattern, 0, sizeof(pattern));
pattern.baseMiniCycleDuration = 0x1; // 12.5ms.
pattern.totalMiniCycles = 0x2; // 2 mini cycles.
pattern.totalFullCycles = times; // Repeat n times.
pattern.startIntensity = 0x0; // 0%.
pattern.baseMiniCycleDuration = 0x1; // 12.5ms.
pattern.totalMiniCycles = 0x2; // 2 mini cycles.
pattern.totalFullCycles = times; // Repeat n times.
pattern.startIntensity = 0x0; // 0%.
pattern.miniCycles[0].ledIntensity = 0xF; // 100%.
pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms.
pattern.miniCycles[1].ledIntensity = 0x0; // 0%.
pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms.
pattern.miniCycles[0].ledIntensity = 0xF; // 100%.
pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms.
pattern.miniCycles[1].ledIntensity = 0x0; // 0%.
pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Total 187.5ms.
pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms.
return pattern;
}
void blinkLed(u8 times)
{
if (g_notificationLedAvailable)
{
if (g_notificationLedAvailable) {
size_t n;
u64 uniquePadIds[2];
HidsysNotificationLedPattern pattern = blinkLedPattern(times);
memset(uniquePadIds, 0, sizeof(uniquePadIds));
Result res = hidsysGetUniquePadsFromNpad(hidGetHandheldMode() ? CONTROLLER_HANDHELD : CONTROLLER_PLAYER_1, uniquePadIds, 2, &n);
if (R_SUCCEEDED(res))
{
for (size_t i = 0; i < n; i++)
{
if (R_SUCCEEDED(res)) {
for (size_t i = 0; i < n; i++) {
hidsysSetNotificationLedPattern(&pattern, uniquePadIds[i]);
}
}