Skip to content

Commit

Permalink
More meaningful errors, more error checking and a few little fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
profi200 committed Jun 9, 2015
1 parent d12d72a commit eded5ec
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 95 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
*~
*.3ds
*.cia
*.smdh
*.3dsx
*.elf
*.smdh
*.bat
*.layout
Thumbs.db
build/
4 changes: 2 additions & 2 deletions _Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ $(RESOURCE)/%.icn : $(RESOURCE)/banner.png $(RESOURCE)/icon24x24.png $(RESOURCE)
.PRECIOUS: $(PROJECT_NAME)_debug.elf
$(PROJECT_NAME)_debug.elf : Makefile
#---------------------------------------------------------------------------------
@make
@make -j4
@cp $(PROJECT_NAME).elf $(PROJECT_NAME)_debug.elf

#---------------------------------------------------------------------------------
.PRECIOUS: %.elf
%.elf : Makefile
#---------------------------------------------------------------------------------
@make
@make -j4


clean :
Expand Down
10 changes: 0 additions & 10 deletions include/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,4 @@



struct error: public std::exception
{
char errStr[256];


error(const char *file, const int line, const Result res) {snprintf(errStr, 255, "%s:%d: Error: 0x%X", file, line, (unsigned int)res);}

virtual const char* what() {return errStr;}
};

#endif // _ERROR_H_
36 changes: 28 additions & 8 deletions include/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,37 @@
#ifndef _FS_H_
#define _FS_H_

#include <exception>
#include <string>
#include <vector>
#include <cstdio>
#include <3ds.h>

#define FS_PATH_MAX_LENGTH (0x106)
#define MAX_BUF_SIZE (0x200000) // 2 MB
#define FS_ERR_DOESNT_EXIST ((Result)0xC8804478)
#define FS_ERR_DOES_ALREADY_EXIST ((Result)0xC82044BE)
#define FS_PATH_MAX_LENGTH (0x106)
#define MAX_BUF_SIZE (0x200000) // 2 MB
#define FS_ERR_DOESNT_EXIST ((Result)0xC8804478)
#define FS_ERR_DOES_ALREADY_EXIST ((Result)0xC82044BE) // Sometimes the API returns 0xC82044B9 instead


extern FS_archive sdmcArchive;

class fsException : public std::exception
{
char errStr[256];
Result res;


public:
fsException(const char *file, const int line, const Result res, const char *desc)
{
this->res = res;
snprintf(errStr, 255, "fsException:\n%s:%d: Result: 0x%X\n%s", file, line, (unsigned int)res, desc);
}

virtual const char* what() {return errStr;}
const Result getErrCode() {return res;}
};

typedef enum
{
FS_SEEK_SET = 0,
Expand All @@ -53,7 +72,7 @@ namespace fs


public:
File(const std::u16string& path, u32 openFlags, FS_archive& archive=sdmcArchive);
File(const std::u16string& path, u32 openFlags, FS_archive& archive=sdmcArchive) {open(path, openFlags, archive);}
File() {}
~File() {close();}

Expand All @@ -68,7 +87,7 @@ namespace fs
void move(const std::u16string& dst, FS_archive& dstArchive=sdmcArchive);
void copy(const std::u16string& dst, FS_archive& dstArchive=sdmcArchive);
void remove(const std::u16string& path, FS_archive& archive=sdmcArchive);
void remove();
void remove(); // Removes the currently opened file

// Don't use setFileHandle() for normal files! Only for AM file handles or similar.
Handle getFileHandle() {return _fileHandle_;}
Expand All @@ -81,6 +100,8 @@ namespace fs
std::u16string name;
bool isDir;
u64 size;

DirEntry(std::u16string name, bool isDir, u64 size) : name(name), isDir(isDir), size(size) {}
};


Expand All @@ -92,7 +113,7 @@ namespace fs
void removeDir(const std::u16string& path, FS_archive& archive=sdmcArchive);


// Removed zip functions
// snipped zip functions


// Misc functions
Expand All @@ -101,7 +122,6 @@ namespace fs
} // namespace fs


//Result FSUSER_ControlArchive(Handle *handle, FS_archive *archive);
void sdmcArchiveInit();
void sdmcArchiveExit();

Expand Down
3 changes: 2 additions & 1 deletion include/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class Buffer
T *ptr;

public:
Buffer(u32 elementCnt) : elements(elementCnt) {ptr = new T[elementCnt];}
// Clears mem by default to avoid problems
Buffer(u32 elementCnt, bool clearMem=true) : elements(elementCnt) {ptr = new T[elementCnt]; if(clearMem) clear();}
~Buffer() {delete[] ptr;}

void clear() {memset(ptr, 0, size());}
Expand Down
27 changes: 23 additions & 4 deletions include/title.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,29 @@
#ifndef _TITLE_H_
#define _TITLE_H_

#include <exception>
#include <string>
#include <vector>
#include <cstdio>
#include <3ds.h>

class titleException : public std::exception
{
char errStr[256];
Result res;


public:
titleException(const char *file, const int line, const Result res, const char *desc)
{
this->res = res;
snprintf(errStr, 255, "titleException:\n%s:%d: Result: 0x%X\n%s", file, line, (unsigned int)res, desc);
}

virtual const char* what() {return errStr;}
const Result getErrCode() {return res;}
};



struct TitleInfo
Expand All @@ -38,8 +57,7 @@ struct TitleInfo
};


/*
struct Icon
/*struct Icon
{
u32 magic;
u16 version;
Expand Down Expand Up @@ -70,12 +88,13 @@ struct Icon
u64 reserved2;
u16 icon24[0x240];
u16 icon48[0x900];
};
*/
};*/


std::vector<TitleInfo> getTitleInfos(mediatypes_enum mediaType);
void installCia(mediatypes_enum mediaType, const std::u16string& path);
void deleteTitle(mediatypes_enum mediaType, u64 titleID);
bool launchTitle(mediatypes_enum mediaType, u8 flags, u64 titleID); // On applet launch it returns false if the applet can't be lauched
#define relaunchApp() launchTitle(mediatype_SDMC, 2, 0)

#endif // _TITLE_H_
Loading

0 comments on commit eded5ec

Please sign in to comment.