make old file load/save shared

This commit is contained in:
Allen Webster 2016-05-27 20:46:22 -04:00
parent f73b8a0a6a
commit a90c33f09b
4 changed files with 60 additions and 65 deletions

View File

@ -309,7 +309,7 @@ draw_font_info_load(Partition *partition,
i32 result = 1; i32 result = 1;
File_Data file; File_Data file;
file = system_load_file(filename.str); file = sysshared_load_file(filename.str);
Temp_Memory temp = begin_temp_memory(partition); Temp_Memory temp = begin_temp_memory(partition);
stbtt_packedchar *chardata = push_array(partition, stbtt_packedchar, 256); stbtt_packedchar *chardata = push_array(partition, stbtt_packedchar, 256);
@ -401,7 +401,7 @@ draw_font_load(void *base_block, i32 size,
i32 result = 1; i32 result = 1;
File_Data file; File_Data file;
file = system_load_file(filename.str); file = sysshared_load_file(filename.str);
Partition partition_ = make_part(base_block, size); Partition partition_ = make_part(base_block, size);
Partition *partition = &partition_; Partition *partition = &partition_;

View File

@ -9,6 +9,39 @@
// TOP // TOP
internal File_Data
sysshared_load_file(char *filename){
File_Data result = {0};
File_Loading loading =
system_file_load_begin(filename);
result.got_file = loading.exists;
if (loading.size > 0){
result.data.size = loading.size;
result.data.data = (byte*)Win32GetMemory(result.data.size);
if (!result.data.data){
system_file_load_end(loading, 0);
result = file_data_zero();
}
else{
if (!system_file_load_end(loading, (char*)result.data.data)){
Win32FreeMemory(result.data.data);
result = file_data_zero();
}
}
}
return(result);
}
internal b32
sysshared_save_file(char *filename, char *data, i32 size){
return(system_file_save(filename, data, size));
}
internal b32 internal b32
usable_ascii(char c){ usable_ascii(char c){
b32 result = 1; b32 result = 1;

View File

@ -27,15 +27,11 @@ file_data_zero(){
#define Sys_Get_Memory_Sig(name) void* name(i32 size, i32 line_number, char *file_name) #define Sys_Get_Memory_Sig(name) void* name(i32 size, i32 line_number, char *file_name)
#define Sys_Free_Memory_Sig(name) void name(void *block) #define Sys_Free_Memory_Sig(name) void name(void *block)
#define Sys_File_Can_Be_Made_Sig(name) b32 name(char *filename) #define Sys_File_Can_Be_Made_Sig(name) b32 name(char *filename)
#define Sys_Load_File_Sig(name) File_Data name(char *filename)
#define Sys_Save_File_Sig(name) b32 name(char *filename, char *data, i32 size)
#define Sys_Get_Binary_Path_Sig(name) i32 name(String *out) #define Sys_Get_Binary_Path_Sig(name) i32 name(String *out)
internal Sys_Get_Memory_Sig(system_get_memory_); internal Sys_Get_Memory_Sig(system_get_memory_);
internal Sys_Free_Memory_Sig(system_free_memory); internal Sys_Free_Memory_Sig(system_free_memory);
internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made); internal Sys_File_Can_Be_Made_Sig(system_file_can_be_made);
internal Sys_Load_File_Sig(system_load_file);
internal Sys_Save_File_Sig(system_save_file);
internal Sys_Get_Binary_Path_Sig(system_get_binary_path); internal Sys_Get_Binary_Path_Sig(system_get_binary_path);
#define system_get_memory(size) system_get_memory_((size), __LINE__, __FILE__) #define system_get_memory(size) system_get_memory_((size), __LINE__, __FILE__)

View File

@ -296,7 +296,16 @@ Sys_File_Load_Begin_Sig(system_file_load_begin){
File_Loading loading = {0}; File_Loading loading = {0};
HANDLE file = 0; HANDLE file = 0;
file = CreateFile(filename, GENERIC_READ, 0, 0, String fname_str = make_string_slowly(filename);
if (fname_str.size < 1024){
char fixed_space[1024];
String fixed_str = make_fixed_width_string(fixed_space);
copy(&fixed_str, fname_str);
terminate_with_null(&fixed_str);
replace_char(fixed_str, '/', '\\');
file = CreateFile(fixed_str.str, GENERIC_READ, 0, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (file && file != INVALID_HANDLE_VALUE){ if (file && file != INVALID_HANDLE_VALUE){
@ -312,6 +321,7 @@ Sys_File_Load_Begin_Sig(system_file_load_begin){
CloseHandle(file); CloseHandle(file);
} }
} }
}
return(loading); return(loading);
} }
@ -369,50 +379,6 @@ Sys_File_Save_Sig(system_file_save){
return(success); return(success);
} }
internal
Sys_Load_File_Sig(system_load_file){
File_Data result = {0};
String fname_str = make_string_slowly(filename);
if (fname_str.size >= 1024) return(result);
char fixed_space[1024];
String fixed_str = make_fixed_width_string(fixed_space);
copy(&fixed_str, fname_str);
terminate_with_null(&fixed_str);
replace_char(fixed_str, '/', '\\');
File_Loading loading =
system_file_load_begin(fixed_str.str);
result.got_file = loading.exists;
if (loading.size > 0){
result.data.size = loading.size;
result.data.data = (byte*)Win32GetMemory(result.data.size);
if (!result.data.data){
system_file_load_end(loading, 0);
result = file_data_zero();
}
else{
if (!system_file_load_end(loading, (char*)result.data.data)){
Win32FreeMemory(result.data.data);
result = file_data_zero();
}
}
}
return(result);
}
// TODO(allen): eliminate this
internal
Sys_Save_File_Sig(system_save_file){
return(system_file_save(filename, data, size));
}
// TODO(allen): THIS system does not really work. // TODO(allen): THIS system does not really work.
// I want to eliminate them both entirely and find a better // I want to eliminate them both entirely and find a better
// way to track the dirty state of files. It shouldn't be too // way to track the dirty state of files. It shouldn't be too
@ -2103,7 +2069,7 @@ int main(int argc, char **argv){
if (file->flags & FEx_Save){ if (file->flags & FEx_Save){
Assert((file->flags & FEx_Request) == 0); Assert((file->flags & FEx_Request) == 0);
file->flags &= (~FEx_Save); file->flags &= (~FEx_Save);
if (system_save_file(file->filename, (char*)file->data, file->size)){ if (sysshared_save_file(file->filename, (char*)file->data, file->size)){
file->flags |= FEx_Save_Complete; file->flags |= FEx_Save_Complete;
} }
else{ else{
@ -2115,7 +2081,7 @@ int main(int argc, char **argv){
if (file->flags & FEx_Request){ if (file->flags & FEx_Request){
Assert((file->flags & FEx_Save) == 0); Assert((file->flags & FEx_Save) == 0);
file->flags &= (~FEx_Request); file->flags &= (~FEx_Request);
File_Data sysfile = system_load_file(file->filename); File_Data sysfile = sysshared_load_file(file->filename);
if (!sysfile.got_file){ if (!sysfile.got_file){
file->flags |= FEx_Not_Exist; file->flags |= FEx_Not_Exist;
} }