Big update
This commit is contained in:
@@ -758,7 +758,11 @@ String16 ToString16(Allocator allocator, String string);
|
||||
wchar_t *ToWidechar(Allocator allocator, String string);
|
||||
int64_t WideLength(wchar_t *string);
|
||||
void NormalizePathInPlace(String s);
|
||||
|
||||
String ChopLastSlash(String s);
|
||||
String ChopLastPeriod(String s);
|
||||
String SkipToLastSlash(String s);
|
||||
String SkipToLastPeriod(String s);
|
||||
String Copy(Allocator allocator, String string);
|
||||
/*
|
||||
Hash table implementation:
|
||||
Pointers to values
|
||||
|
||||
@@ -19,15 +19,20 @@ struct FileIter {
|
||||
};
|
||||
|
||||
String ReadFile(Allocator arena, String path);
|
||||
bool WriteFile(String path, String data);
|
||||
String GetAbsolutePath(Allocator arena, String relative);
|
||||
bool IsValid(const FileIter &it);
|
||||
void Advance(FileIter *it);
|
||||
FileIter IterateFiles(Allocator allocator, String path);
|
||||
bool InitOS();
|
||||
|
||||
String GetExePath(Allocator allocator);
|
||||
String GetExeDir(Allocator allocator);
|
||||
|
||||
struct Process {
|
||||
bool is_valid;
|
||||
char platform[32];
|
||||
bool is_valid;
|
||||
String error_message;
|
||||
char platform[32];
|
||||
};
|
||||
|
||||
Process RunEx(String cmd);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user