Big update

This commit is contained in:
Krzosa Karol
2024-07-12 08:27:19 +02:00
parent 37982e0448
commit 9891a302ac
5 changed files with 261 additions and 162 deletions

View File

@@ -59,8 +59,8 @@ Process RunEx(String args) {
NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL);
LocalFree(lpMsgBuf);
printf("Failed to create process \ncmd: %.*s\nwindows_message: %s", FmtString(args), (char *)lpMsgBuf);
Assert(!"Failed to create process");
// @warning: leak! but we don't care
result.error_message = Format(GetSystemAllocator(), "Failed to create process | message: %s | cmd: %.*s", (char *)lpMsgBuf, FmtString(args));
}
return result;
}
@@ -228,4 +228,45 @@ double get_time_in_micros(void) {
clock_gettime(CLOCK_MONOTONIC, &spec);
return (((double)spec.tv_sec) * 1000000) + (((double)spec.tv_nsec) / 1000);
}
#endif
#endif
bool WriteFile(String path, String data) {
bool result = false;
wchar_t wpath[1024];
CreateWidecharFromChar(wpath, Lengthof(wpath), path.data, path.len);
DWORD access = GENERIC_WRITE;
DWORD creation_disposition = CREATE_ALWAYS;
HANDLE handle = CreateFileW(wpath, access, 0, NULL, creation_disposition, FILE_ATTRIBUTE_NORMAL, NULL);
if (handle != INVALID_HANDLE_VALUE) {
DWORD bytes_written = 0;
Assert(data.len == (DWORD)data.len); // @Todo: can only read 32 byte size files?
BOOL error = WriteFile(handle, data.data, (DWORD)data.len, &bytes_written, NULL);
if (error == TRUE) {
if (bytes_written == data.len) {
result = true;
}
}
CloseHandle(handle);
}
return result;
}
String GetExePath(Allocator allocator) {
wchar_t wbuffer[1024];
DWORD wsize = GetModuleFileNameW(0, wbuffer, Lengthof(wbuffer));
Assert(wsize != 0);
String path = ToString(allocator, wbuffer, wsize);
NormalizePathInPlace(path);
return path;
}
String GetExeDir(Allocator allocator) {
Scratch scratch;
String path = GetExePath(scratch);
path = ChopLastSlash(path);
path = Copy(allocator, path);
return path;
}