New file attributes by handle and by name everywhere

master
Allen Webster 2019-02-13 16:24:03 -08:00
parent 9cfffe6bb6
commit b2b4270505
13 changed files with 85 additions and 117 deletions

View File

@ -547,7 +547,9 @@ get_file_list(Application_Links *app, char *dir, int32_t len){
static bool32
file_exists(Application_Links *app, char *file_name, int32_t len){
return(file_exists(app, make_string(file_name, len)));
File_Attributes attributes = {};
file_get_attributes(app, make_string(file_name, len), &attributes);
return(attributes.last_write_time > 0);
}
static bool32

View File

@ -6,7 +6,7 @@
static Hard_Start_Result
buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, int32_t line_start, int32_t tab_width){
tab_width -= 1;
int32_t tab_additional_width = tab_width - 1;
Hard_Start_Result result = {};
result.all_space = true;
@ -32,7 +32,7 @@ buffer_find_hard_start(Application_Links *app, Buffer_Summary *buffer, int32_t l
}
if (c == '\t'){
result.indent_pos += tab_width;
result.indent_pos += tab_additional_width;
}
if (c != ' '){

View File

@ -122,7 +122,7 @@ struct Application_Links;
#define MEMORY_ALLOCATE_SIG(n) void* n(Application_Links *app, int32_t size)
#define MEMORY_SET_PROTECTION_SIG(n) bool32 n(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags)
#define MEMORY_FREE_SIG(n) void n(Application_Links *app, void *ptr, int32_t size)
#define FILE_EXISTS_SIG(n) bool32 n(Application_Links *app, String file_name)
#define FILE_GET_ATTRIBUTES_SIG(n) bool32 n(Application_Links *app, String file_name, File_Attributes *attributes_out)
#define DIRECTORY_CD_SIG(n) bool32 n(Application_Links *app, String *directory, String relative_path)
#define GET_4ED_PATH_SIG(n) bool32 n(Application_Links *app, String *path_out, int32_t *required_size_out)
#define SHOW_MOUSE_CURSOR_SIG(n) void n(Application_Links *app, Mouse_Cursor_Show_Type show)
@ -259,7 +259,7 @@ typedef SET_GUI_UP_DOWN_KEYS_SIG(Set_GUI_Up_Down_Keys_Function);
typedef MEMORY_ALLOCATE_SIG(Memory_Allocate_Function);
typedef MEMORY_SET_PROTECTION_SIG(Memory_Set_Protection_Function);
typedef MEMORY_FREE_SIG(Memory_Free_Function);
typedef FILE_EXISTS_SIG(File_Exists_Function);
typedef FILE_GET_ATTRIBUTES_SIG(File_Get_Attributes_Function);
typedef DIRECTORY_CD_SIG(Directory_CD_Function);
typedef GET_4ED_PATH_SIG(Get_4ed_Path_Function);
typedef SHOW_MOUSE_CURSOR_SIG(Show_Mouse_Cursor_Function);
@ -398,7 +398,7 @@ Set_GUI_Up_Down_Keys_Function *set_gui_up_down_keys;
Memory_Allocate_Function *memory_allocate;
Memory_Set_Protection_Function *memory_set_protection;
Memory_Free_Function *memory_free;
File_Exists_Function *file_exists;
File_Get_Attributes_Function *file_get_attributes;
Directory_CD_Function *directory_cd;
Get_4ed_Path_Function *get_4ed_path;
Show_Mouse_Cursor_Function *show_mouse_cursor;
@ -536,7 +536,7 @@ Set_GUI_Up_Down_Keys_Function *set_gui_up_down_keys_;
Memory_Allocate_Function *memory_allocate_;
Memory_Set_Protection_Function *memory_set_protection_;
Memory_Free_Function *memory_free_;
File_Exists_Function *file_exists_;
File_Get_Attributes_Function *file_get_attributes_;
Directory_CD_Function *directory_cd_;
Get_4ed_Path_Function *get_4ed_path_;
Show_Mouse_Cursor_Function *show_mouse_cursor_;
@ -682,7 +682,7 @@ app_links->set_gui_up_down_keys_ = Set_GUI_Up_Down_Keys;\
app_links->memory_allocate_ = Memory_Allocate;\
app_links->memory_set_protection_ = Memory_Set_Protection;\
app_links->memory_free_ = Memory_Free;\
app_links->file_exists_ = File_Exists;\
app_links->file_get_attributes_ = File_Get_Attributes;\
app_links->directory_cd_ = Directory_CD;\
app_links->get_4ed_path_ = Get_4ed_Path;\
app_links->show_mouse_cursor_ = Show_Mouse_Cursor;\
@ -820,7 +820,7 @@ static void set_gui_up_down_keys(Application_Links *app, Key_Code up_key, Key_Mo
static void* memory_allocate(Application_Links *app, int32_t size){return(app->memory_allocate(app, size));}
static bool32 memory_set_protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags){return(app->memory_set_protection(app, ptr, size, flags));}
static void memory_free(Application_Links *app, void *ptr, int32_t size){(app->memory_free(app, ptr, size));}
static bool32 file_exists(Application_Links *app, String file_name){return(app->file_exists(app, file_name));}
static bool32 file_get_attributes(Application_Links *app, String file_name, File_Attributes *attributes_out){return(app->file_get_attributes(app, file_name, attributes_out));}
static bool32 directory_cd(Application_Links *app, String *directory, String relative_path){return(app->directory_cd(app, directory, relative_path));}
static bool32 get_4ed_path(Application_Links *app, String *path_out, int32_t *required_size_out){return(app->get_4ed_path(app, path_out, required_size_out));}
static void show_mouse_cursor(Application_Links *app, Mouse_Cursor_Show_Type show){(app->show_mouse_cursor(app, show));}
@ -958,7 +958,7 @@ static void set_gui_up_down_keys(Application_Links *app, Key_Code up_key, Key_Mo
static void* memory_allocate(Application_Links *app, int32_t size){return(app->memory_allocate_(app, size));}
static bool32 memory_set_protection(Application_Links *app, void *ptr, int32_t size, Memory_Protect_Flags flags){return(app->memory_set_protection_(app, ptr, size, flags));}
static void memory_free(Application_Links *app, void *ptr, int32_t size){(app->memory_free_(app, ptr, size));}
static bool32 file_exists(Application_Links *app, String file_name){return(app->file_exists_(app, file_name));}
static bool32 file_get_attributes(Application_Links *app, String file_name, File_Attributes *attributes_out){return(app->file_get_attributes_(app, file_name, attributes_out));}
static bool32 directory_cd(Application_Links *app, String *directory, String relative_path){return(app->directory_cd_(app, directory, relative_path));}
static bool32 get_4ed_path(Application_Links *app, String *path_out, int32_t *required_size_out){return(app->get_4ed_path_(app, path_out, required_size_out));}
static void show_mouse_cursor(Application_Links *app, Mouse_Cursor_Show_Type show){(app->show_mouse_cursor_(app, show));}

View File

@ -1006,7 +1006,6 @@ App_Step_Sig(app_step){
file_name = cl_file_name;
}
//open_file(system, models, file_name);
Buffer_ID id = 0;
create_buffer(&models->app_links, file_name, 0, &id);
}

View File

@ -3942,8 +3942,7 @@ DOC_SEE(memory_allocate)
DOC_SEE(Memory_Protect_Flags)
*/{
Models *models = (Models*)app->cmd_context;
bool32 result = models->system->memory_set_protection(ptr, size, flags);
return(result);
return(models->system->memory_set_protection(ptr, size, flags));
}
API_EXPORT void
@ -3958,16 +3957,12 @@ DOC_SEE(memory_allocate)
models->system->memory_free(ptr, size);
}
// TODO(allen): redocument
API_EXPORT bool32
File_Exists(Application_Links *app, String file_name)
/*
DOC_PARAM(filename, This parameter specifies the full path to a file; it need not be null terminated.)
DOC_PARAM(len, This parameter specifies the length of the filename string.)
DOC_RETURN(This call returns non-zero if and only if the file exists.)
*/{
File_Get_Attributes(Application_Links *app, String file_name, File_Attributes *attributes_out)
{
Models *models = (Models*)app->cmd_context;
return(models->system->file_exists(file_name.str, file_name.size));
*attributes_out = models->system->quick_file_attributes(file_name);
return(attributes_out->last_write_time > 0);
}
// TODO(allen): redocument

View File

@ -422,7 +422,7 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
block_zero_struct(&file->state);
Gap_Buffer_Init init = buffer_begin_init(&file->state.buffer, val.str, val.size);
for (; buffer_init_need_more(&init); ){
for (;buffer_init_need_more(&init);){
i32 page_size = buffer_init_page_size(&init);
page_size = l_round_up_i32(page_size, KB(4));
if (page_size < KB(4)){
@ -448,15 +448,13 @@ file_create_from_string(System_Functions *system, Models *models, Editing_File *
Font_Pointers font = system->font.get_pointers_by_id(font_id);
Assert(font.valid);
{
file_measure_starts(heap, &file->state.buffer);
file_allocate_character_starts_as_needed(heap, file);
buffer_measure_character_starts(system, font, &file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
file_measure_wraps(system, &models->mem, file, font);
//adjust_views_looking_at_files_to_new_cursor(system, models, file);
}
file_measure_starts(heap, &file->state.buffer);
file_allocate_character_starts_as_needed(heap, file);
buffer_measure_character_starts(system, font, &file->state.buffer, file->state.character_starts, 0, file->settings.virtual_white);
file_measure_wraps(system, &models->mem, file, font);
//adjust_views_looking_at_files_to_new_cursor(system, models, file);
file->lifetime_object = lifetime_alloc_object(heap, &models->lifetime_allocator, DynamicWorkspace_Buffer, file);

View File

@ -31,6 +31,9 @@ typedef Sys_Set_File_List_Sig(System_Set_File_List);
typedef Sys_Get_Canonical_Sig(System_Get_Canonical);
// file load/save
#define Sys_Quick_File_Attributes_Sig(name) File_Attributes name(String file_name)
typedef Sys_Quick_File_Attributes_Sig(System_Quick_File_Attributes);
#define Sys_Load_Handle_Sig(name) b32 name(char *filename, Plat_Handle *handle_out)
typedef Sys_Load_Handle_Sig(System_Load_Handle);
@ -198,9 +201,6 @@ typedef Sys_Memory_Set_Protection_Sig(System_Memory_Set_Protection);
typedef Sys_Memory_Free_Sig(System_Memory_Free);
// file system
#define Sys_File_Exists_Sig(name) b32 name(char *filename, i32 len)
typedef Sys_File_Exists_Sig(System_File_Exists);
#define Sys_Directory_CD_Sig(name) bool32 name(char *dir, i32 *len, i32 cap, char *rel_path, i32 rel_len)
typedef Sys_Directory_CD_Sig(System_Directory_CD);
@ -224,23 +224,21 @@ typedef Sys_Is_Fullscreen_Sig(System_Is_Fullscreen);
#define Sys_Log_Sig(name) void name(char *message, u32 length)
typedef Sys_Log_Sig(System_Log);
#define INTERNAL_Sys_Get_Thread_States_Sig(name) void name(Thread_Group_ID id, b8 *running, i32 *pending)
typedef INTERNAL_Sys_Get_Thread_States_Sig(INTERNAL_System_Get_Thread_States);
struct System_Functions{
Font_Functions font;
// files (tracked api): 10
System_Set_File_List *set_file_list;
System_Get_Canonical *get_canonical;
System_Add_Listener *add_listener;
System_Remove_Listener *remove_listener;
System_Get_File_Change *get_file_change;
System_Load_Handle *load_handle;
System_Load_Attributes *load_attributes;
System_Load_File *load_file;
System_Load_Close *load_close;
System_Save_File *save_file;
// files (tracked api): 11
System_Set_File_List *set_file_list;
System_Get_Canonical *get_canonical;
System_Add_Listener *add_listener;
System_Remove_Listener *remove_listener;
System_Get_File_Change *get_file_change;
System_Quick_File_Attributes *quick_file_attributes;
System_Load_Handle *load_handle;
System_Load_Attributes *load_attributes;
System_Load_File *load_file;
System_Load_Close *load_close;
System_Save_File *save_file;
// time: 4
System_Now_Time *now_time;
@ -271,12 +269,11 @@ struct System_Functions{
System_Acquire_Lock *acquire_lock;
System_Release_Lock *release_lock;
// custom: 10
// custom: 9
System_Memory_Allocate *memory_allocate;
System_Memory_Set_Protection *memory_set_protection;
System_Memory_Free *memory_free;
System_File_Exists *file_exists;
System_Directory_CD *directory_cd;
System_Get_Current_Path *get_current_path;
System_Get_4ed_Path *get_4ed_path;
@ -287,7 +284,6 @@ struct System_Functions{
// debug: 1
System_Log *log;
INTERNAL_System_Get_Thread_States *internal_get_thread_states;
};
#endif

View File

@ -491,9 +491,7 @@ buffer_unbind_name_low_level(Working_Set *working_set, Editing_File *file){
}
internal void
buffer_bind_name(Models *models, Heap *heap, Partition *scratch,
Working_Set *working_set,
Editing_File *file, String base_name){
buffer_bind_name(Models *models, Heap *heap, Partition *scratch, Working_Set *working_set, Editing_File *file, String base_name){
Temp_Memory temp = begin_temp_memory(scratch);
// List of conflict files.

View File

@ -20,6 +20,7 @@ link_system_code(){
SYSLINK(add_listener);
SYSLINK(remove_listener);
SYSLINK(get_file_change);
SYSLINK(quick_file_attributes);
SYSLINK(load_handle);
SYSLINK(load_attributes);
SYSLINK(load_file);
@ -54,7 +55,6 @@ link_system_code(){
SYSLINK(memory_set_protection);
SYSLINK(memory_free);
SYSLINK(file_exists);
SYSLINK(directory_cd);
SYSLINK(get_current_path);
SYSLINK(get_4ed_path);
@ -64,9 +64,6 @@ link_system_code(){
SYSLINK(show_mouse_cursor);
SYSLINK(log);
#if defined(FRED_INTERNAL)
SYSLINK(internal_get_thread_states);
#endif
}
// BOTTOM

View File

@ -351,23 +351,6 @@ Sys_Grow_Thread_Memory_Sig(system_grow_thread_memory){
system_release_lock(cancel_lock);
}
internal
INTERNAL_Sys_Get_Thread_States_Sig(system_internal_get_thread_states){
Thread_Group *group = threadvars.groups + id;
Work_Queue *queue = threadvars.queues + id;
Unbounded_Work_Queue *source_queue = &group->queue;
u32 write = queue->write_position;
u32 read = queue->read_position;
if (write < read){
write += QUEUE_WRAP;
}
*pending = (i32)(write - read) + source_queue->count - source_queue->skip;
for (i32 i = 0; i < group->count; ++i){
running[i] = (group->threads[i].running != 0);
}
}
internal void
work_system_init(){
AssertThreadSizes();

View File

@ -344,6 +344,17 @@ win32_file_attributes_from_HANDLE(HANDLE file){
return(result);
}
internal
Sys_Quick_File_Attributes_Sig(system_quick_file_attributes){
WIN32_FILE_ATTRIBUTE_DATA info = {};
File_Attributes result = {};
if (GetFileAttributesEx_utf8String(&shared_vars.scratch, file_name, GetFileExInfoStandard, &info)){
result.size = ((u64)info.nFileSizeHigh << 32LL) | ((u64)info.nFileSizeLow);
result.last_write_time = ((u64)info.ftLastWriteTime.dwHighDateTime << 32LL) | ((u64)info.ftLastWriteTime.dwLowDateTime);
}
return(result);
}
internal
Sys_Load_Handle_Sig(system_load_handle){
b32 result = false;
@ -416,29 +427,6 @@ Sys_Save_File_Sig(system_save_file){
// File System
//
internal
Sys_File_Exists_Sig(system_file_exists){
char full_filename_space[1024];
String full_filename;
HANDLE file;
b32 result = 0;
if (len < sizeof(full_filename_space)){
full_filename = make_fixed_width_string(full_filename_space);
copy_ss(&full_filename, make_string(filename, len));
terminate_with_null(&full_filename);
file = CreateFile_utf8(&shared_vars.scratch, (u8*)full_filename.str, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if (file != INVALID_HANDLE_VALUE){
CloseHandle(file);
result = 1;
}
}
return(result);
}
internal b32
system_directory_exists(char *path){
DWORD attrib = GetFileAttributes_utf8(&shared_vars.scratch, (u8*)path);

View File

@ -13,30 +13,35 @@
#define FRED_WIN32_UTF8_CPP
internal Win32_UTF16
input_8_to_16(Partition *scratch, u8 *in){
input_8_to_16(Partition *scratch, u8 *in, u32 in_length){
Win32_UTF16 r = {};
u32 utf8_len = 0;
for (;in[utf8_len];++utf8_len);
u32 utf16_max = (utf8_len + 1)*2;
u32 utf16_max = (in_length + 1)*2;
u16 *utf16 = push_array(scratch, u16, utf16_max);
b32 error = false;
u32 utf16_len = (u32)utf8_to_utf16_minimal_checking(utf16, utf16_max - 1, in, utf8_len, &error);
u32 utf16_len = (u32)utf8_to_utf16_minimal_checking(utf16, utf16_max - 1, in, in_length, &error);
if (!error && utf16_len < utf16_max){
utf16[utf16_len] = 0;
r.success = true;
r.utf8_len = utf8_len;
r.utf8_len = in_length;
r.utf16_max = utf16_max;
r.utf16_len = utf16_len;
r.utf16 = utf16;
}
return(r);
}
internal Win32_UTF16
input_8_to_16(Partition *scratch, u8 *in){
u32 length = 0;
for (;in[length];++length);
return(input_8_to_16(scratch, in, length));
}
internal Win32_UTF16
input_8_to_16(Partition *scratch, String in){
return(input_8_to_16(scratch, (u8*)in.str, in.size));
}
internal HANDLE
CreateFile_utf8(Partition *scratch, u8 *name, DWORD access, DWORD share, LPSECURITY_ATTRIBUTES security, DWORD creation, DWORD flags, HANDLE template_file){
HANDLE result = INVALID_HANDLE_VALUE;
@ -191,9 +196,7 @@ GetCurrentDirectory_utf8(Partition *scratch, DWORD max, u8 *buffer){
internal int
MessageBox_utf8(Partition *scratch, HWND owner, u8 *text, u8 *caption, UINT type){
int result = 0;
Temp_Memory temp = begin_temp_memory(scratch);
Win32_UTF16 text_16 = input_8_to_16(scratch, text);
if (text_16.success){
Win32_UTF16 caption_16 = input_8_to_16(scratch, caption);
@ -201,25 +204,31 @@ MessageBox_utf8(Partition *scratch, HWND owner, u8 *text, u8 *caption, UINT type
result = MessageBoxW(owner, (LPWSTR)text_16.utf16, (LPWSTR)caption_16.utf16, type);
}
}
end_temp_memory(temp);
return(result);
}
internal BOOL
SetWindowText_utf8(Partition *scratch, HWND window, u8 *string){
BOOL result = FALSE;
Temp_Memory temp = begin_temp_memory(scratch);
Win32_UTF16 string_16 = input_8_to_16(scratch, string);
if (string_16.success){
result = SetWindowTextW(window, (LPWSTR)string_16.utf16);
}
end_temp_memory(temp);
return(result);
}
internal BOOL
GetFileAttributesEx_utf8String(Partition *scratch, String file_name, GET_FILEEX_INFO_LEVELS info_level_id, LPVOID file_info){
BOOL result = FALSE;
Temp_Memory temp = begin_temp_memory(scratch);
Win32_UTF16 string_16 = input_8_to_16(scratch, file_name);
if (string_16.success){
result = GetFileAttributesExW((LPWSTR)string_16.utf16, info_level_id, file_info);
}
end_temp_memory(temp);
return(result);
}

View File

@ -39,6 +39,9 @@ MessageBox_utf8(Partition *scratch, HWND owner, u8 *text, u8 *caption, UINT type
internal BOOL
SetWindowText_utf8(Partition *scratch, HWND window, u8 *string);
internal BOOL
GetFileAttributesEx_utf8String(Partition *scratch, String file_name, GET_FILEEX_INFO_LEVELS info_level_id, LPVOID file_info);
// For implementation
struct Win32_UTF16{