From 7ada40c1bc547a87fefdd7f77ee5de5b3fa5f9ff Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Fri, 26 Aug 2016 15:35:50 -0400 Subject: [PATCH] fixes to new save system --- 4ed_api_implementation.cpp | 87 +++++++++++++++++++++----------------- 4ed_file_view.cpp | 3 +- win32_4ed.cpp | 4 +- 3 files changed, 52 insertions(+), 42 deletions(-) diff --git a/4ed_api_implementation.cpp b/4ed_api_implementation.cpp index 8e1a8435..088aeb95 100644 --- a/4ed_api_implementation.cpp +++ b/4ed_api_implementation.cpp @@ -985,17 +985,26 @@ DOC_SEE(Buffer_Create_Flag) String fname = make_string(filename, filename_len); Temp_Memory temp = begin_temp_memory(part); + if (filename != 0){ - Editing_File_Canon_Name canon; + Editing_File *file = 0; + b32 do_new_file = false; + Plat_Handle handle = {0}; + Editing_File_Canon_Name canon = {0}; if (get_canon_name(system, &canon, fname)){ - Editing_File *file = working_set_canon_contains(working_set, canon.name); - - if (file == 0){ - b32 do_new_file = false; - - Plat_Handle handle = {0}; - + file = working_set_canon_contains(working_set, canon.name); + } + else{ + do_new_file = true; + } + + if (!file){ + file = working_set_name_contains(working_set, fname); + } + + if (!file){ + if (!do_new_file){ if (flags & BufferCreate_AlwaysNew){ do_new_file = true; } @@ -1004,49 +1013,49 @@ DOC_SEE(Buffer_Create_Flag) do_new_file = true; } } + } + + if (!do_new_file){ + Assert(!handle_equal(handle, handle_zero())); - if (!do_new_file){ - Assert(!handle_equal(handle, handle_zero())); - - i32 size = system->load_size(handle); - b32 in_general_mem = false; - char *buffer = push_array(part, char, size); - - if (buffer == 0){ - buffer = (char*)general_memory_allocate(general, size); - Assert(buffer != 0); - in_general_mem = true; - } - - if (system->load_file(handle, buffer, size)){ - file = working_set_alloc_always(working_set, general); - if (file){ - buffer_bind_file(general, working_set, file, canon.name); - buffer_bind_name(general, working_set, file, fname); - init_normal_file(system, models, file, buffer, size); - fill_buffer_summary(&result, file, cmd); - } - } - - if (in_general_mem){ - general_memory_free(general, buffer); - } - - system->load_close(handle); + i32 size = system->load_size(handle); + b32 in_general_mem = false; + char *buffer = push_array(part, char, size); + + if (buffer == 0){ + buffer = (char*)general_memory_allocate(general, size); + Assert(buffer != 0); + in_general_mem = true; } - else{ + + if (system->load_file(handle, buffer, size)){ file = working_set_alloc_always(working_set, general); if (file){ + buffer_bind_file(general, working_set, file, canon.name); buffer_bind_name(general, working_set, file, fname); - init_normal_file(system, models, file, 0, 0); + init_normal_file(system, models, file, buffer, size); fill_buffer_summary(&result, file, cmd); } } + + if (in_general_mem){ + general_memory_free(general, buffer); + } + + system->load_close(handle); } else{ - fill_buffer_summary(&result, file, cmd); + file = working_set_alloc_always(working_set, general); + if (file){ + buffer_bind_name(general, working_set, file, fname); + init_normal_file(system, models, file, 0, 0); + fill_buffer_summary(&result, file, cmd); + } } } + else{ + fill_buffer_summary(&result, file, cmd); + } } end_temp_memory(temp); diff --git a/4ed_file_view.cpp b/4ed_file_view.cpp index 7e786cdb..ce1559b5 100644 --- a/4ed_file_view.cpp +++ b/4ed_file_view.cpp @@ -1022,14 +1022,12 @@ file_create_from_string(System_Functions *system, Models *models, i32 scratch_size = partition_remaining(part); Assert(scratch_size > 0); - b32 init_success = buffer_end_init(&init, part->base + part->pos, scratch_size); AllowLocal(init_success); Assert(init_success); if (buffer_size(&file->state.buffer) < val.size){ file->settings.dos_write_mode = 1; } - file_synchronize_times(system, file); i16 font_id = models->global_font.font_id; @@ -1037,6 +1035,7 @@ file_create_from_string(System_Functions *system, Models *models, Render_Font *font = get_font_info(font_set, font_id)->font; float *advance_data = 0; if (font) advance_data = font->advance_data; + file_measure_starts_widths(system, general, &file->state.buffer, advance_data); file->settings.read_only = read_only; diff --git a/win32_4ed.cpp b/win32_4ed.cpp index d79f3a0c..5e541099 100644 --- a/win32_4ed.cpp +++ b/win32_4ed.cpp @@ -1281,7 +1281,7 @@ Sys_Save_File_Sig(system_save_file){ GENERIC_WRITE, 0, 0, - CREATE_NEW, + CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); @@ -1298,6 +1298,8 @@ Sys_Save_File_Sig(system_save_file){ } written_total += written_size; } + + CloseHandle(file); } return(result);