14#define IS_READ_ONLY_MODE(m) ((m) && (m)[0] == 'r' && !strchr((m), '+'))
32 "File_OpenWithMode failed for \"%s\" (mode \"%s\"): %s",
50 return mode && (strchr(mode,
'w') || strchr(mode,
'a') || strchr(mode,
'+'));
57 if (path && path[0]) {
58 CreateDirectoryA(path,
NULL);
87 sds dir = sdsnew(buf);
130 sds redirected = sdsnew(buf);
152 sds msg = sdscatprintf(
154 "Failed to open \"%s\" (mode \"%s\"). This file will not be written.\n\n%s",
168 const int perms = ((mode && strchr(mode,
'r')) ? _S_IREAD : 0)
169 | (wants_write ? _S_IWRITE : 0);
172 "Permission error opening \"%s\" (mode \"%s\"): %s",
178 sds prompt = sdscatprintf(
180 "Failed to open file \"%s\" (mode \"%s\"): %s\n\n"
181 "This is typically the result of a permissions issue, especially if you're "
184 "Try granting permissions 0o%03o?",
191 const SDL_MessageBoxButtonData buttons[] = {
192 {SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 0,
"No"},
193 {SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1,
"Yes"},
196 const SDL_MessageBoxData msgbox = {
197 .flags = SDL_MESSAGEBOX_WARNING,
199 .title =
"DttR: File Permission Error",
209 if (button_id != 1) {
222 "chmod didn't resolve permission error for \"%s\": %s",
231 char resolved[MAX_PATH];
234 DTTR_LOG_DEBUG(
"Resolved case-insensitive read \"%s\" -> \"%s\"", path, resolved);
238 char cached[MAX_PATH];
243 DTTR_LOG_DEBUG(
"Resolved ISO-backed read \"%s\" -> \"%s\"", path, cached);
252 char redirected[MAX_PATH];
253 path =
redirect_path(path, redirected,
sizeof(redirected), mode);
268 DTTR_LOG_ERROR(
"File \"%s\" does not exist; passing to game.", path);
273 const bool is_perm_error
274 = (errno == EACCES || errno == EPERM || (errno == EBADF && wants_write));
283 "Failed to open \"%s\" (mode \"%s\"): %s",
DTTR_Graphics_COM_DirectDrawSurface7 DWORD flags void NULL
#define DTTR_LOG_DEBUG(...)
#define DTTR_LOG_ERROR(...)
bool DTTR_Path_CopySds(char *out, size_t out_size, sds value)
bool DTTR_Path_ExactExists(const char *path)
bool DTTR_Path_AppendSegment(sds *path, const char *segment, char separator)
bool DTTR_Path_IsSafeRelative(const char *path)
DTTR_PCDOGS_API const struct dttr_pcdogs_function_accessor_File_OpenWithMode *const DTTR_PCDOGS_F_File_OpenWithMode
Accessor object for File_OpenWithMode.
bool DTTR_ResultOK(DTTR_Result result)
bool DTTR_SDL_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
bool DTTR_SDL_ShowSimpleMessageBox(SDL_MessageBoxFlags flags, const char *title, const char *message, SDL_Window *window)
const DTTR_Core_Context * dttr_sidecar_runtime_context()
char dttr_exe_hash[DTTR_EXE_HASH_LENGTH+1]
char dttr_loader_dir[MAX_PATH]
bool dttr_game_data_resolve_read_path(const char *path, char *out_path, size_t out_path_size)
bool dttr_game_data_resolve_existing_read_path(const char *path, char *out_path, size_t out_path_size)
#define IS_READ_ONLY_MODE(m)
static void ensure_save_dir()
static DTTR_PCDOGS_T_File_Handle * try_open_read_path(const char *path, const char *mode)
static DTTR_PCDOGS_T_File_Handle * file_open_with_mode(const char *path, const char *mode, uint8_t sharing_flag)
static DTTR_PCDOGS_T_File_Handle * report_file_open_failure(const char *path, const char *mode)
static const char * redirect_path(const char *path, char *buf, size_t buf_size, const char *mode)
static bool redirect_saves_initialized
DTTR_PCDOGS_T_File_Handle * dttr_crt_hook_open_file_callback(const char *path, const char *mode)
static bool mode_wants_write(const char *mode)
static bool is_relative_path(const char *path)
static void build_saves_dir(char *buf, size_t buf_size)
static DTTR_PCDOGS_T_File_Handle * try_fix_permissions(const char *path, const char *mode)
static void create_dir_if_set(const char *path)
static void build_save_slot_dir(char *buf, size_t buf_size)
static const char * dttr_sidecar_result_detail(DTTR_Result result)
CRT-compatible file handle layout, used by package and asset loading streams.