fixed cart name loaded from cmd
This commit is contained in:
parent
4f7f2e924c
commit
221998d1c4
|
@ -213,8 +213,10 @@ static void commandDoneLine(Console* console, bool newLine)
|
|||
if(newLine)
|
||||
printLine(console);
|
||||
|
||||
if(strlen(fsGetDir(console->fs)))
|
||||
printBack(console, fsGetDir(console->fs));
|
||||
char dir[FILENAME_MAX];
|
||||
fsGetDir(console->fs, dir);
|
||||
if(strlen(dir))
|
||||
printBack(console, dir);
|
||||
|
||||
printFront(console, ">");
|
||||
}
|
||||
|
@ -2854,7 +2856,9 @@ static bool cmdLoadCart(Console* console, const char* name)
|
|||
if(hasProjectExt(name))
|
||||
{
|
||||
loadProject(console, name, data, size, console->embed.file);
|
||||
setCartName(console, fsFilename(name));
|
||||
char cartName[FILENAME_MAX];
|
||||
fsFilename(name, cartName);
|
||||
setCartName(console, cartName);
|
||||
console->embed.yes = true;
|
||||
console->skipStart = true;
|
||||
done = true;
|
||||
|
@ -2864,8 +2868,13 @@ static bool cmdLoadCart(Console* console, const char* name)
|
|||
|
||||
if(hasExt(name, CART_EXT))
|
||||
{
|
||||
loadCart(console->tic, console->embed.file, data, size, true);
|
||||
setCartName(console, fsFilename(name));
|
||||
loadCart(console->tic, console->embed.file, data, size, true);
|
||||
|
||||
char cartName[FILENAME_MAX];
|
||||
fsFilename(name, cartName);
|
||||
|
||||
setCartName(console, cartName);
|
||||
|
||||
console->embed.yes = true;
|
||||
done = true;
|
||||
}
|
||||
|
|
20
src/fs.c
20
src/fs.c
|
@ -523,9 +523,9 @@ void fsDirBack(FileSystem* fs)
|
|||
*ptr = '\0';
|
||||
}
|
||||
|
||||
const char* fsGetDir(FileSystem* fs)
|
||||
void fsGetDir(FileSystem* fs, char* dir)
|
||||
{
|
||||
return fs->work;
|
||||
strcpy(dir, fs->work);
|
||||
}
|
||||
|
||||
bool fsChangeDir(FileSystem* fs, const char* dir)
|
||||
|
@ -753,6 +753,7 @@ static void fsFullname(const char *path, char *fullname)
|
|||
freeString(pathString);
|
||||
|
||||
const char* res = stringToUtf8(wpath);
|
||||
|
||||
#else
|
||||
|
||||
const char* res = realpath(path, NULL);
|
||||
|
@ -763,17 +764,18 @@ static void fsFullname(const char *path, char *fullname)
|
|||
free((void*)res);
|
||||
}
|
||||
|
||||
const char* fsFilename(const char *path)
|
||||
void fsFilename(const char *path, char* out)
|
||||
{
|
||||
static char full[FILENAME_MAX];
|
||||
char full[FILENAME_MAX];
|
||||
fsFullname(path, full);
|
||||
|
||||
const char* base = fsBasename(path);
|
||||
char base[FILENAME_MAX];
|
||||
fsBasename(path, base);
|
||||
|
||||
return base ? full + strlen(fsBasename(path)) : NULL;
|
||||
strcpy(out, full + strlen(base));
|
||||
}
|
||||
|
||||
const char* fsBasename(const char *path)
|
||||
void fsBasename(const char *path, char* out)
|
||||
{
|
||||
char* result = NULL;
|
||||
|
||||
|
@ -784,7 +786,7 @@ const char* fsBasename(const char *path)
|
|||
#endif
|
||||
|
||||
{
|
||||
static char full[FILENAME_MAX];
|
||||
char full[FILENAME_MAX];
|
||||
fsFullname(path, full);
|
||||
|
||||
struct tic_stat_struct s;
|
||||
|
@ -818,7 +820,7 @@ const char* fsBasename(const char *path)
|
|||
if(result && result[strlen(result)-1] != SEP[0])
|
||||
strcat(result, SEP);
|
||||
|
||||
return result;
|
||||
strcpy(out, result);
|
||||
}
|
||||
|
||||
bool fsExists(const char* name)
|
||||
|
|
6
src/fs.h
6
src/fs.h
|
@ -62,8 +62,8 @@ void fsMakeDir(FileSystem* fs, const char* name);
|
|||
bool fsExistsFile(FileSystem* fs, const char* name);
|
||||
u64 fsMDate(FileSystem* fs, const char* name);
|
||||
|
||||
const char* fsBasename(const char *path);
|
||||
const char* fsFilename(const char *path);
|
||||
void fsBasename(const char *path, char* out);
|
||||
void fsFilename(const char *path, char* out);
|
||||
bool fsExists(const char* name);
|
||||
void* fsReadFile(const char* path, s32* size);
|
||||
bool fsWriteFile(const char* path, const void* data, s32 size);
|
||||
|
@ -74,6 +74,6 @@ void fsOpenWorkingFolder(FileSystem* fs);
|
|||
bool fsIsDir(FileSystem* fs, const char* dir);
|
||||
bool fsIsInPublicDir(FileSystem* fs);
|
||||
bool fsChangeDir(FileSystem* fs, const char* dir);
|
||||
const char* fsGetDir(FileSystem* fs);
|
||||
void fsGetDir(FileSystem* fs, char* out);
|
||||
void fsDirBack(FileSystem* fs);
|
||||
void fsHomeDir(FileSystem* fs);
|
|
@ -1809,7 +1809,13 @@ Studio* studioInit(s32 argc, char **argv, s32 samplerate, const char* folder, Sy
|
|||
|
||||
impl.system = system;
|
||||
|
||||
impl.fs = createFileSystem(argc > 1 && fsExists(argv[1]) ? fsBasename(argv[1]) : folder);
|
||||
if(argc > 1 && fsExists(argv[1]))
|
||||
{
|
||||
char name[FILENAME_MAX];
|
||||
fsBasename(argv[1], name);
|
||||
impl.fs = createFileSystem(name);
|
||||
}
|
||||
else impl.fs = createFileSystem(folder);
|
||||
|
||||
impl.tic80local = (tic80_local*)tic80_create(impl.samplerate);
|
||||
impl.studio.tic = impl.tic80local->memory;
|
||||
|
|
20
src/surf.c
20
src/surf.c
|
@ -226,9 +226,10 @@ static void drawBottomToolbar(Surf* surf, s32 x, s32 y)
|
|||
tic->api.rect(tic, x, y + Height, TIC80_WIDTH, 1, tic_color_black);
|
||||
{
|
||||
char label[FILENAME_MAX];
|
||||
char dir[FILENAME_MAX];
|
||||
fsGetDir(surf->fs, dir);
|
||||
|
||||
sprintf(label, "/%s", fsGetDir(surf->fs));
|
||||
|
||||
sprintf(label, "/%s", dir);
|
||||
s32 xl = x + MAIN_OFFSET;
|
||||
s32 yl = y + (Height - TIC_FONT_HEIGHT)/2;
|
||||
tic->api.text(tic, label, xl, yl+1, tic_color_black);
|
||||
|
@ -576,7 +577,10 @@ static void initMenu(Surf* surf)
|
|||
.surf = surf,
|
||||
};
|
||||
|
||||
if(strcmp(fsGetDir(surf->fs), "") != 0)
|
||||
char dir[FILENAME_MAX];
|
||||
fsGetDir(surf->fs, dir);
|
||||
|
||||
if(strcmp(dir, "") != 0)
|
||||
addMenuItem("..", NULL, 0, &data, true);
|
||||
|
||||
fsEnumFiles(surf->fs, addMenuItem, &data);
|
||||
|
@ -588,12 +592,13 @@ static void initMenu(Surf* surf)
|
|||
static void onGoBackDir(Surf* surf)
|
||||
{
|
||||
char last[FILENAME_MAX];
|
||||
strcpy(last, fsGetDir(surf->fs));
|
||||
fsGetDir(surf->fs, last);
|
||||
|
||||
fsDirBack(surf->fs);
|
||||
initMenu(surf);
|
||||
|
||||
const char* current = fsGetDir(surf->fs);
|
||||
char current[FILENAME_MAX];
|
||||
fsGetDir(surf->fs, current);
|
||||
|
||||
for(s32 i = 0; i < surf->menu.count; i++)
|
||||
{
|
||||
|
@ -628,7 +633,10 @@ static void changeDirectory(Surf* surf, const char* dir)
|
|||
{
|
||||
if(strcmp(dir, "..") == 0)
|
||||
{
|
||||
if(strcmp(fsGetDir(surf->fs), "") != 0)
|
||||
char dir[FILENAME_MAX];
|
||||
fsGetDir(surf->fs, dir);
|
||||
|
||||
if(strcmp(dir, "") != 0)
|
||||
{
|
||||
playSystemSfx(2);
|
||||
resetMovie(surf, &MenuRightHideState, onGoBackDir);
|
||||
|
|
Loading…
Reference in New Issue