Browse Source

Return result of directory creation, so that the game may handle creation errors

console
Nico de Poel 5 years ago
parent
commit
78f42d9c9a
  1. 6
      Assets/Scripts/Modules/SystemModule.Interop.cs
  2. 12
      Assets/Scripts/Modules/SystemModule.cs
  3. 9
      engine/UniQuake/sys_uniquake.c

6
Assets/Scripts/Modules/SystemModule.Interop.cs

@ -151,11 +151,11 @@ public partial class SystemModule: CallbackHandler<SystemModule>
} }
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate void SysMkDirCallback(IntPtr target, [MarshalAs(UnmanagedType.LPStr)] string path);
private delegate bool SysMkDirCallback(IntPtr target, [MarshalAs(UnmanagedType.LPStr)] string path);
[MonoPInvokeCallback(typeof(SysMkDirCallback))] [MonoPInvokeCallback(typeof(SysMkDirCallback))]
private static void Callback_SysMkDir(IntPtr target, string path)
private static bool Callback_SysMkDir(IntPtr target, string path)
{ {
GetSelf(target).MkDir(path);
return GetSelf(target).MkDir(path);
} }
} }

12
Assets/Scripts/Modules/SystemModule.cs

@ -70,6 +70,8 @@ public partial class SystemModule
private int FileOpenWrite(string path) private int FileOpenWrite(string path)
{ {
// TODO: we could use this method to redirect user config & save data to a platform-specific user storage
int i = FindFileHandle(); int i = FindFileHandle();
try try
{ {
@ -155,15 +157,17 @@ public partial class SystemModule
return File.Exists(path) ? 1 : -1; return File.Exists(path) ? 1 : -1;
} }
private void MkDir(string path)
private bool MkDir(string path)
{ {
try try
{ {
Directory.CreateDirectory(path);
var info = Directory.CreateDirectory(path);
return info.Exists;
} }
catch
catch (Exception ex)
{ {
Debug.LogWarning($"Could not create directory: {path}");
Debug.LogWarning($"Could not create directory {path}, reason: {ex.Message}");
return false;
} }
} }
} }

9
engine/UniQuake/sys_uniquake.c

@ -18,7 +18,7 @@ typedef struct unity_syscalls_s
int(*SysFileRead)(void *target, int handle, void *dest, int count); int(*SysFileRead)(void *target, int handle, void *dest, int count);
int(*SysFileWrite)(void *target, int handle, const void *data, int count); int(*SysFileWrite)(void *target, int handle, const void *data, int count);
int(*SysFileTime)(void *target, const char *path); int(*SysFileTime)(void *target, const char *path);
void(*SysMkDir)(void *target, const char *path);
qboolean(*SysMkDir)(void *target, const char *path);
} unity_syscalls_t; } unity_syscalls_t;
const unity_syscalls_t *unity_syscalls; const unity_syscalls_t *unity_syscalls;
@ -94,11 +94,8 @@ int Sys_FileTime(const char *path)
void Sys_mkdir(const char *path) void Sys_mkdir(const char *path)
{ {
unity_syscalls->SysMkDir(unity_syscalls->target, path);
// TODO: handle creation errors
/*if (GetLastError() != ERROR_ALREADY_EXISTS)
Sys_Error("Unable to create directory %s", path);*/
if (!unity_syscalls->SysMkDir(unity_syscalls->target, path))
Sys_Error("Unable to create directory %s", path);
} }
void Sys_Sleep_New(unsigned long msecs) void Sys_Sleep_New(unsigned long msecs)

Loading…
Cancel
Save