1
0
Fork 0
mirror of https://github.com/suchmememanyskill/TegraExplorer.git synced 2024-11-09 13:41:45 +00:00

[Untested] implement some more fs functions

This commit is contained in:
suchmememanyskill 2021-07-25 17:49:00 +02:00
parent e423a612ce
commit db3ba94b5a
4 changed files with 79 additions and 15 deletions

View file

@ -44,7 +44,7 @@ dump={
if(ncatype(fp)==1){name=name- 4+".cnmt.nca"} if(ncatype(fp)==1){name=name- 4+".cnmt.nca"}
color(0x00FF00) color(0x00FF00)
print("\r["+i.str()+"/"+c+"]", x) print("\r["+i.str()+"/"+c+"]", x)
if(filecopy(fp,bsp+"/"+name)){println("\nErr during copy")pe()} if(copyfile(fp,bsp+"/"+name)){println("\nErr during copy")pe()}
i=i+1 i=i+1
} }
} }

View file

@ -179,6 +179,9 @@
<ClInclude Include="unsolvedArrayClass.h" /> <ClInclude Include="unsolvedArrayClass.h" />
<ClInclude Include="vector.h" /> <ClInclude Include="vector.h" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="input.te" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">
</ImportGroup> </ImportGroup>

View file

@ -144,4 +144,9 @@
<Filter>Source Files\Classes\Elseable</Filter> <Filter>Source Files\Classes\Elseable</Filter>
</ClInclude> </ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="input.te">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
</Project> </Project>

View file

@ -23,6 +23,7 @@
#include "../storage/emummc.h" #include "../storage/emummc.h"
#include <utils/util.h> #include <utils/util.h>
#include "../fs/fsutils.h" #include "../fs/fsutils.h"
#include <storage/nx_sd.h>
#endif #endif
// Takes [int, function]. Returns elseable. // Takes [int, function]. Returns elseable.
ClassFunction(stdIf) { ClassFunction(stdIf) {
@ -356,6 +357,36 @@ ClassFunction(stdFileDel){
return newIntVariablePtr(f_unlink(args[0]->string.value)); return newIntVariablePtr(f_unlink(args[0]->string.value));
} }
ClassFunction(stdCopyDir){
return newIntVariablePtr(FolderCopy(args[0]->string.value, args[1]->string.value).err);
}
ClassFunction(stdFileMove){
return newIntVariablePtr(f_rename(args[0]->string.value, args[1]->string.value));
}
ClassFunction(stdFileRead){
u32 fSize = 0;
u8 *buff = sd_file_read(args[0]->string.value, &fSize);
if (buff == NULL){
SCRIPT_FATAL_ERR("Failed to read file");
}
Vector_t vec = vecFromArray(buff, fSize, sizeof(u8));
Variable_t v = {.variableType = ByteArrayClass, .solvedArray.vector = vec};
return copyVariableToPtr(v);
}
ClassFunction(stdFileWrite){
return newIntVariablePtr(sd_save_to_file(args[1]->solvedArray.vector.data, args[1]->solvedArray.vector.count, args[0]->string.value));
}
extern int launch_payload(char *path);
ClassFunction(stdLaunchPayload){
return newIntVariablePtr(launch_payload(args[0]->string.value));
}
#else #else
#define STUBBED(name) ClassFunction(name) { return newIntVariablePtr(0); } #define STUBBED(name) ClassFunction(name) { return newIntVariablePtr(0); }
@ -400,6 +431,11 @@ STUBBED(stdClear)
STUBBED(stdRmDir) STUBBED(stdRmDir)
STUBBED(stdFileExists) STUBBED(stdFileExists)
STUBBED(stdFileDel) STUBBED(stdFileDel)
STUBBED(stdCopyDir)
STUBBED(stdFileMove)
STUBBED(stdLaunchPayload)
STUBBED(stdFileWrite)
STUBBED(stdFileRead)
#endif #endif
u8 oneIntoneFunction[] = { IntClass, FunctionClass }; u8 oneIntoneFunction[] = { IntClass, FunctionClass };
@ -409,35 +445,55 @@ u8 threeIntsStd[] = { IntClass, IntClass, IntClass };
u8 twoStringArgStd[] = {StringClass, StringClass}; u8 twoStringArgStd[] = {StringClass, StringClass};
u8 oneIntStd[] = {IntClass}; u8 oneIntStd[] = {IntClass};
u8 menuArgsStd[] = {StringArrayClass, IntClass, IntArrayClass}; u8 menuArgsStd[] = {StringArrayClass, IntClass, IntArrayClass};
u8 oneStringOneByteArrayStd[] = {StringClass, ByteArrayClass};
ClassFunctionTableEntry_t standardFunctionDefenitions[] = { ClassFunctionTableEntry_t standardFunctionDefenitions[] = {
// Flow control
{"if", stdIf, 2, oneIntoneFunction}, {"if", stdIf, 2, oneIntoneFunction},
{"while", stdWhile, 2, doubleFunctionClass}, {"while", stdWhile, 2, doubleFunctionClass},
{"print", stdPrint, VARARGCOUNT, 0},
{"println", stdPrintLn, VARARGCOUNT, 0},
{"mountsys", stdMountSysmmc, 1, oneStringArgStd},
{"mountemu", stdMountEmummc, 1, oneStringArgStd},
{"readsave", stdMountSave, 1, oneStringArgStd},
{"exit", stdExit, 0, 0}, {"exit", stdExit, 0, 0},
{"break", stdBreak, 0, 0}, {"break", stdBreak, 0, 0},
// Class creation
{"readsave", stdMountSave, 1, oneStringArgStd},
{"dict", stdDict, 0, 0}, {"dict", stdDict, 0, 0},
{"setpixel", stdSetPixel, 3, threeIntsStd},
{"readdir", stdReadDir, 1, oneStringArgStd}, // Utils
{"filecopy", stdFileCopy, 2, twoStringArgStd}, {"print", stdPrint, VARARGCOUNT, 0},
{"mkdir", stdMkdir, 1, oneStringArgStd}, {"println", stdPrintLn, VARARGCOUNT, 0},
{"setpixel", stdSetPixel, 3, threeIntsStd}, // TODO: change for setblock
{"emu", stdHasEmu, 0, 0},
{"clear", stdClear, 0, 0},
{"timer", stdGetMs, 0, 0},
{"memory", stdGetMemUsage, 0, 0}, {"memory", stdGetMemUsage, 0, 0},
{"ncatype", stdGetNcaType, 1, oneStringArgStd},
{"pause", stdPauseMask, 1, oneIntStd}, {"pause", stdPauseMask, 1, oneIntStd},
{"pause", stdPause, 0, 0}, {"pause", stdPause, 0, 0},
{"color", stdColor, 1, oneIntStd}, {"color", stdColor, 1, oneIntStd},
{"menu", stdMenuFull, 3, menuArgsStd}, {"menu", stdMenuFull, 3, menuArgsStd},
{"menu", stdMenuFull, 2, menuArgsStd}, {"menu", stdMenuFull, 2, menuArgsStd},
{"emu", stdHasEmu, 0, 0},
{"clear", stdClear, 0, 0}, // System
{"timer", stdGetMs, 0, 0}, {"mountsys", stdMountSysmmc, 1, oneStringArgStd},
{"mountemu", stdMountEmummc, 1, oneStringArgStd},
{"ncatype", stdGetNcaType, 1, oneStringArgStd},
// FileSystem
// Dir
{"readdir", stdReadDir, 1, oneStringArgStd},
{"deldir", stdRmDir, 1, oneStringArgStd}, {"deldir", stdRmDir, 1, oneStringArgStd},
{"fsexists", stdFileExists, 1, oneStringArgStd}, {"mkdir", stdMkdir, 1, oneStringArgStd},
{"copydir", stdCopyDir, 2, twoStringArgStd},
// File
{"copyfile", stdFileCopy, 2, twoStringArgStd},
{"movefile", stdFileMove, 2, twoStringArgStd},
{"delfile", stdFileDel, 1, oneStringArgStd}, {"delfile", stdFileDel, 1, oneStringArgStd},
{"readfile", stdFileRead, 1, oneStringArgStd},
{"writefile", stdFileWrite, 2, oneStringOneByteArrayStd},
// Utils
{"fsexists", stdFileExists, 1, oneStringArgStd},
{"payload", stdLaunchPayload, 1, oneStringArgStd},
}; };
ClassFunctionTableEntry_t* searchStdLib(char* funcName, u8 *len) { ClassFunctionTableEntry_t* searchStdLib(char* funcName, u8 *len) {