WIP Windows impl.

This commit is contained in:
Stephen Seo 2024-07-05 15:00:50 +09:00
parent 58269d751c
commit 3f74beefdc

View file

@ -31,6 +31,10 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#elif SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_WINDOWS
#include <Windows.h>
#include <fileapi.h>
#include <winnt.h>
#endif
#include "data_structures/hash_map.h"
@ -61,7 +65,11 @@ unsigned int simple_archiver_parser_internal_filename_idx(
} else if ((flags & 3) == 1) {
if (filename[idx] == 0) {
return known_good_idx;
#if SIMPLE_ARCHIVER_PLATFORM != SIMPLE_ARCHIVER_PLATFORM_WINDOWS
} else if (filename[idx] == '/') {
#else
} else if (filename[idx] == '\\') {
#endif
flags |= 2;
} else {
return idx - 1;
@ -69,7 +77,11 @@ unsigned int simple_archiver_parser_internal_filename_idx(
} else if ((flags & 3) == 3) {
if (filename[idx] == 0) {
return known_good_idx;
#if SIMPLE_ARCHIVER_PLATFORM != SIMPLE_ARCHIVER_PLATFORM_WINDOWS
} else if (filename[idx] == '/') {
#else
} else if (filename[idx] == '\\') {
#endif
continue;
} else if (filename[idx] == '.') {
flags &= 0xFFFFFFFC;
@ -103,6 +115,34 @@ void simple_archiver_parser_internal_remove_end_slash(char *filename) {
}
}
char *simple_archiver_internal_forward_to_backward_slash(const char *string) {
unsigned int len = strlen(string) + 1;
char *backward_slash_string = malloc(len);
strncpy(backward_slash_string, string, len);
for (unsigned int idx = 0; idx < len; ++idx) {
if (backward_slash_string[idx] == '/') {
backward_slash_string[idx] = '\\';
}
}
return backward_slash_string;
}
char *simple_archiver_internal_backward_to_forward_slash(const char *string) {
unsigned int len = strlen(string) + 1;
char *forward_slash_string = malloc(len);
strncpy(forward_slash_string, string, len);
for (unsigned int idx = 0; idx < len; ++idx) {
if (forward_slash_string[idx] == '\\') {
forward_slash_string[idx] = '/';
}
}
return forward_slash_string;
}
void simple_archiver_internal_free_file_info_fn(void *data) {
SDArchiverFileInfo *file_info = data;
if (file_info) {
@ -418,6 +458,8 @@ SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
// Unhandled type. TODO handle this.
}
}
#elif SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_WINDOWS
/* DWORD file_stats = GetFileAttributesA(*/
#endif
// Remove leading "./" entries from files_list.