fix: add path qualification to Files app pathbar
This commit is contained in:
@@ -12,4 +12,4 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MONTAUK_BUILD_NUMBER 42
|
||||
#define MONTAUK_BUILD_NUMBER 43
|
||||
|
||||
@@ -164,6 +164,42 @@ void filemanager_cancel_pathbar(FileManagerState* fm) {
|
||||
fm->pathbar_editing = false;
|
||||
}
|
||||
|
||||
// True if `path` begins with a "N:/" volume prefix (one or more digits then ":/").
|
||||
static bool filemanager_has_volume_prefix(const char* path) {
|
||||
int i = 0;
|
||||
while (path[i] >= '0' && path[i] <= '9') i++;
|
||||
return i > 0 && path[i] == ':' && path[i + 1] == '/';
|
||||
}
|
||||
|
||||
// Resolve a user-typed path into a fully-qualified "N:/..." path. Paths without
|
||||
// a volume number (e.g. "/os" or "os") are drive-relative; the kernel resolves
|
||||
// them against drive 0, but filemanager_read_dir strips a drive-root-relative
|
||||
// prefix, so an unqualified path would leave the returned basenames with their
|
||||
// full sub-path. Qualify it here so the prefix stripping matches. The drive of
|
||||
// the current location is preferred, falling back to drive 0.
|
||||
static void filemanager_qualify_path(FileManagerState* fm, char* out, int out_max) {
|
||||
const char* in = fm->pathbar_buf;
|
||||
if (filemanager_has_volume_prefix(in)) {
|
||||
montauk::strcpy(out, in);
|
||||
return;
|
||||
}
|
||||
|
||||
char drive[8] = "0";
|
||||
if (filemanager_has_volume_prefix(fm->current_path)) {
|
||||
int i = 0;
|
||||
while (fm->current_path[i] >= '0' && fm->current_path[i] <= '9' && i < 6) {
|
||||
drive[i] = fm->current_path[i];
|
||||
i++;
|
||||
}
|
||||
drive[i] = '\0';
|
||||
}
|
||||
|
||||
montauk::strcpy(out, drive);
|
||||
str_append(out, ":", out_max);
|
||||
if (in[0] != '/') str_append(out, "/", out_max);
|
||||
str_append(out, in, out_max);
|
||||
}
|
||||
|
||||
void filemanager_commit_pathbar(FileManagerState* fm) {
|
||||
fm->pathbar_editing = false;
|
||||
if (fm->pathbar_len == 0) {
|
||||
@@ -171,7 +207,7 @@ void filemanager_commit_pathbar(FileManagerState* fm) {
|
||||
filemanager_push_history(fm);
|
||||
return;
|
||||
}
|
||||
montauk::strcpy(fm->current_path, fm->pathbar_buf);
|
||||
filemanager_qualify_path(fm, fm->current_path, sizeof(fm->current_path));
|
||||
filemanager_read_dir(fm);
|
||||
filemanager_push_history(fm);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user