mirror of https://github.com/AxioDL/metaforce.git
Add RecrusiveMakeDir
This commit is contained in:
parent
140e584bf8
commit
ae9b2309cf
|
@ -264,7 +264,11 @@ def recursive_cook(buffer, obj, version, path_hasher, parent_name):
|
|||
angMtx[2][0], angMtx[2][1], angMtx[2][2],
|
||||
0.0, 0.0, 0.0, 0, 0)
|
||||
|
||||
ch_list = []
|
||||
for ch in obj.children:
|
||||
ch_list.append((ch.pass_index, ch.name))
|
||||
for s_pair in sorted(ch_list):
|
||||
ch = bpy.data.objects[s_pair[1]]
|
||||
if ch.retro_widget_type != 'RETRO_NONE':
|
||||
recursive_cook(buffer, ch, version, path_hasher, obj.name)
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ static inline void MakeDir(const char* dir)
|
|||
HRESULT err;
|
||||
if (!CreateDirectoryA(dir, NULL))
|
||||
if ((err = GetLastError()) != ERROR_ALREADY_EXISTS)
|
||||
LogModule.report(logvisor::Fatal, _S("MakeDir(%s)"), dir);
|
||||
LogModule.report(logvisor::Fatal, "MakeDir(%s)", dir);
|
||||
#else
|
||||
if (mkdir(dir, 0755))
|
||||
if (errno != EEXIST)
|
||||
|
@ -196,6 +196,8 @@ static inline void MakeDir(const wchar_t* dir)
|
|||
}
|
||||
#endif
|
||||
|
||||
int RecursiveMakeDir(const SystemChar* dir);
|
||||
|
||||
static inline const SystemChar* GetEnv(const SystemChar* name)
|
||||
{
|
||||
#if HECL_UCS2
|
||||
|
|
|
@ -645,4 +645,103 @@ std::wstring Char16ToWide(const std::u16string& src)
|
|||
return std::wstring(src.begin(), src.end());
|
||||
}
|
||||
|
||||
/* recursive mkdir */
|
||||
#if _WIN32
|
||||
int RecursiveMakeDir(const SystemChar* dir) {
|
||||
SystemChar tmp[1024];
|
||||
SystemChar *p = nullptr;
|
||||
Sstat sb;
|
||||
size_t len;
|
||||
|
||||
/* copy path */
|
||||
wcsncpy(tmp, dir, 1024);
|
||||
len = wcslen(tmp);
|
||||
if (len >= 1024) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* remove trailing slash */
|
||||
if(tmp[len - 1] == '/' || tmp[len - 1] == '\\') {
|
||||
tmp[len - 1] = 0;
|
||||
}
|
||||
|
||||
/* recursive mkdir */
|
||||
for(p = tmp + 1; *p; p++) {
|
||||
if(*p == '/' || *p == '\\') {
|
||||
*p = 0;
|
||||
/* test path */
|
||||
if (Stat(tmp, &sb) != 0) {
|
||||
/* path does not exist - create directory */
|
||||
if (!CreateDirectoryW(tmp, nullptr)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!S_ISDIR(sb.st_mode)) {
|
||||
/* not a directory */
|
||||
return -1;
|
||||
}
|
||||
*p = '/';
|
||||
}
|
||||
}
|
||||
/* test path */
|
||||
if (Stat(tmp, &sb) != 0) {
|
||||
/* path does not exist - create directory */
|
||||
if (!CreateDirectoryW(tmp, nullptr)) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!S_ISDIR(sb.st_mode)) {
|
||||
/* not a directory */
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int RecursiveMakeDir(const SystemChar* dir) {
|
||||
SystemChar tmp[1024];
|
||||
SystemChar *p = nullptr;
|
||||
Sstat sb;
|
||||
size_t len;
|
||||
|
||||
/* copy path */
|
||||
strncpy(tmp, dir, 1024);
|
||||
len = strlen(tmp);
|
||||
if (len >= 1024) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* remove trailing slash */
|
||||
if(tmp[len - 1] == '/') {
|
||||
tmp[len - 1] = 0;
|
||||
}
|
||||
|
||||
/* recursive mkdir */
|
||||
for(p = tmp + 1; *p; p++) {
|
||||
if(*p == '/') {
|
||||
*p = 0;
|
||||
/* test path */
|
||||
if (Stat(tmp, &sb) != 0) {
|
||||
/* path does not exist - create directory */
|
||||
if (mkdir(tmp, 0755) < 0) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!S_ISDIR(sb.st_mode)) {
|
||||
/* not a directory */
|
||||
return -1;
|
||||
}
|
||||
*p = '/';
|
||||
}
|
||||
}
|
||||
/* test path */
|
||||
if (Stat(tmp, &sb) != 0) {
|
||||
/* path does not exist - create directory */
|
||||
if (mkdir(tmp, 0755) < 0) {
|
||||
return -1;
|
||||
}
|
||||
} else if (!S_ISDIR(sb.st_mode)) {
|
||||
/* not a directory */
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue