Eliminate Directory_Exists API

This commit is contained in:
UnknownShadow200 2021-01-13 21:23:11 +11:00
parent d496d87de6
commit 1eefe36cfe
5 changed files with 9 additions and 34 deletions

View File

@ -122,10 +122,8 @@ static cc_bool CreateLogsDirectory(void) {
/* --> Utils_EnsureDirectory --> Logger_SysWarn2 --> Chat_Add --> AppendChatLog -> OpenChatLog */
/* --> Utils_EnsureDirectory --> Logger_SysWarn2 --> Chat_Add --> AppendChatLog ... */
/* and so on, until eventually the stack overflows */
if (Directory_Exists(&dir)) return true;
res = Directory_Create(&dir);
if (!res) return true;
if (!res || res == ReturnCode_DirectoryExists) return true;
Chat_DisableLogging();
Logger_SysWarn2(res, "creating directory", &dir);

View File

@ -76,10 +76,6 @@ static CC_NOINLINE void InitFramebuffer(void) {
Window_AllocFramebuffer(&Launcher_Framebuffer);
}
static cc_bool UsingBitmappedFont(void) {
return (useBitmappedFont || Launcher_ClassicBackground) && hasBitmappedFont;
}
/*########################################################################################################################*
*--------------------------------------------------------Starter/Updater--------------------------------------------------*
@ -504,7 +500,7 @@ void Launcher_TryLoadTexturePack(void) {
void Launcher_UpdateLogoFont(void) {
Font_Free(&logoFont);
Drawer2D_BitmappedText = UsingBitmappedFont();
Drawer2D_BitmappedText = (useBitmappedFont || Launcher_ClassicBackground) && hasBitmappedFont;
Drawer2D_MakeFont(&logoFont, 32, FONT_FLAGS_NONE);
Drawer2D_BitmappedText = false;
}
@ -554,7 +550,6 @@ void Launcher_ResetPixels(void) {
Launcher_ResetArea(0, 0, WindowInfo.Width, WindowInfo.Height);
}
Drawer2D_BitmappedText = UsingBitmappedFont();
DrawTextArgs_Make(&args, &title_fore, &logoFont, false);
x = WindowInfo.Width / 2 - Drawer2D_TextWidth(&args) / 2;
@ -562,8 +557,6 @@ void Launcher_ResetPixels(void) {
Drawer2D_DrawText(&Launcher_Framebuffer, &args, x + titleX, titleY);
args.text = title_fore;
Drawer2D_DrawText(&Launcher_Framebuffer, &args, x, 0);
Drawer2D_BitmappedText = false;
Launcher_MarkAllDirty();
}

View File

@ -31,6 +31,7 @@ const cc_result ReturnCode_FileShareViolation = ERROR_SHARING_VIOLATION;
const cc_result ReturnCode_FileNotFound = ERROR_FILE_NOT_FOUND;
const cc_result ReturnCode_SocketInProgess = WSAEINPROGRESS;
const cc_result ReturnCode_SocketWouldBlock = WSAEWOULDBLOCK;
const cc_result ReturnCode_DirectoryExists = ERROR_ALREADY_EXISTS;
#elif defined CC_BUILD_POSIX
/* POSIX can be shared between Linux/BSD/macOS */
#include <errno.h>
@ -58,6 +59,7 @@ const cc_result ReturnCode_FileShareViolation = 1000000000; /* TODO: not used ap
const cc_result ReturnCode_FileNotFound = ENOENT;
const cc_result ReturnCode_SocketInProgess = EINPROGRESS;
const cc_result ReturnCode_SocketWouldBlock = EWOULDBLOCK;
const cc_result ReturnCode_DirectoryExists = EEXIST;
#endif
/* Platform specific include files (Try to share for UNIX-ish) */
#if defined CC_BUILD_DARWIN
@ -334,15 +336,6 @@ cc_uint64 Stopwatch_Measure(void) {
*-----------------------------------------------------Directory/File------------------------------------------------------*
*#########################################################################################################################*/
#if defined CC_BUILD_WIN
int Directory_Exists(const cc_string* path) {
WCHAR str[NATIVE_STR_LEN];
DWORD attribs;
Platform_EncodeUtf16(str, path);
attribs = GetFileAttributesW(str);
return attribs != INVALID_FILE_ATTRIBUTES && (attribs & FILE_ATTRIBUTE_DIRECTORY);
}
cc_result Directory_Create(const cc_string* path) {
WCHAR str[NATIVE_STR_LEN];
BOOL success;
@ -460,13 +453,6 @@ cc_result File_Length(cc_file file, cc_uint32* len) {
return *len != INVALID_FILE_SIZE ? 0 : GetLastError();
}
#elif defined CC_BUILD_POSIX
int Directory_Exists(const cc_string* path) {
char str[NATIVE_STR_LEN];
struct stat sb;
Platform_EncodeUtf8(str, path);
return stat(str, &sb) == 0 && S_ISDIR(sb.st_mode);
}
cc_result Directory_Create(const cc_string* path) {
char str[NATIVE_STR_LEN];
Platform_EncodeUtf8(str, path);

View File

@ -29,6 +29,7 @@ extern const cc_result ReturnCode_FileShareViolation;
extern const cc_result ReturnCode_FileNotFound;
extern const cc_result ReturnCode_SocketInProgess;
extern const cc_result ReturnCode_SocketWouldBlock;
extern const cc_result ReturnCode_DirectoryExists;
#ifdef CC_BUILD_WIN
/* Encodes a string in UTF16 format, also null terminating the string. */
@ -151,8 +152,6 @@ CC_API cc_uint64 Stopwatch_ElapsedMicroseconds(cc_uint64 beg, cc_uint64 end);
/* Returns total elapsed milliseconds between two stopwatch measurements. */
int Stopwatch_ElapsedMS(cc_uint64 beg, cc_uint64 end);
/* Returns non-zero if the given directory exists. */
CC_API int Directory_Exists(const cc_string* path);
/* Attempts to create a new directory. */
CC_API cc_result Directory_Create(const cc_string* path);
/* Callback function invoked for each file found. */

View File

@ -25,12 +25,11 @@ cc_bool Utils_IsUrlPrefix(const cc_string* value) {
cc_bool Utils_EnsureDirectory(const char* dirName) {
cc_string dir = String_FromReadonly(dirName);
cc_result res;
if (Directory_Exists(&dir)) return true;
cc_result res = Directory_Create(&dir);
res = Directory_Create(&dir);
if (res) { Logger_SysWarn2(res, "creating directory", &dir); }
return res == 0;
if (!res || res == ReturnCode_DirectoryExists) return true;
Logger_SysWarn2(res, "creating directory", &dir);
return false;
}
void Utils_UNSAFE_GetFilename(STRING_REF cc_string* path) {