Skip to content

Commit c24e29e

Browse files
fix: ensure all nested directories are created
1 parent fa8658f commit c24e29e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/filesystem.cpp

+14-9
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,37 @@
33
#include <string>
44
#include <direct.h>
55
#include <fstream>
6-
6+
#include <sys/stat.h>
77
#include "xboxkrnl.h"
88

99
namespace filesystem
1010
{
1111
void create_nested_dirs(const char *path)
1212
{
13+
if (!path || !*path)
14+
return;
15+
1316
char temp_path[256];
14-
strncpy(temp_path, path, sizeof(temp_path));
17+
strncpy(temp_path, path, sizeof(temp_path) - 1);
18+
temp_path[sizeof(temp_path) - 1] = '\0';
1519

1620
char *p = temp_path;
17-
while (*p)
21+
22+
// Skip leading drive letter (e.g., "C:\") or "game:\" prefix
23+
if ((p[0] && p[1] == ':') || strncmp(p, "game:\\", 6) == 0)
24+
p += (p[1] == ':' ? 3 : 6); // Move past "C:\" or "game:\"
25+
26+
for (; *p; p++)
1827
{
1928
if (*p == '\\' || *p == '/')
2029
{
2130
*p = '\0';
22-
23-
// Create the directory if it doesn't exist
24-
_mkdir(temp_path);
25-
31+
_mkdir(temp_path); // Attempt to create the directory
2632
*p = '\\';
2733
}
28-
p++;
2934
}
3035

31-
_mkdir(temp_path);
36+
_mkdir(temp_path); // Create final directory
3237
}
3338

3439
/**

0 commit comments

Comments
 (0)