Rename tmp to .tmp and hide on Windows (Will test after making this commit)

This commit is contained in:
Agent X 2024-05-15 18:00:08 -04:00
parent 12aff40090
commit 591261fd41
7 changed files with 39 additions and 14 deletions

View File

@ -419,8 +419,8 @@ static void DynOS_Tex_GeneratePack_Recursive(const SysPath &aPackFolder, SysPath
} }
// skip files that have already been generated // skip files that have already been generated
char buffer[1024]; char buffer[SYS_MAX_PATH];
snprintf(buffer, 1024, "%s.tex", _Path.substr(0, _Path.size() - 4).c_str()); snprintf(buffer, SYS_MAX_PATH, "%s.tex", _Path.substr(0, _Path.size() - 4).c_str());
if (fs_sys_file_exists(buffer)) { if (fs_sys_file_exists(buffer)) {
continue; continue;
} }

View File

@ -6,6 +6,10 @@
#include "pc/debuglog.h" #include "pc/debuglog.h"
#include "pc/loading.h" #include "pc/loading.h"
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#endif
#define MAX_SESSION_CHARS 7 #define MAX_SESSION_CHARS 7
struct Mods gLocalMods = { 0 }; struct Mods gLocalMods = { 0 };
@ -113,7 +117,12 @@ bool mods_generate_remote_base_path(void) {
LOG_ERROR("Failed to concat tmp path"); LOG_ERROR("Failed to concat tmp path");
return false; return false;
} }
if (!fs_sys_dir_exists(tmpPath)) { fs_sys_mkdir(tmpPath); } if (!fs_sys_dir_exists(tmpPath)) {
fs_sys_mkdir(tmpPath);
#if defined(_WIN32) || defined(_WIN64)
SetFileAttributesA(tmpPath, FILE_ATTRIBUTE_HIDDEN);
#endif
}
// generate session // generate session
char session[MAX_SESSION_CHARS + 1] = { 0 }; char session[MAX_SESSION_CHARS + 1] = { 0 };

View File

@ -8,7 +8,7 @@
#define MAX_MOD_SIZE (35 * 1048576) // 35MB #define MAX_MOD_SIZE (35 * 1048576) // 35MB
#define MOD_DIRECTORY "mods" #define MOD_DIRECTORY "mods"
#define TMP_DIRECTORY "tmp" #define TMP_DIRECTORY ".tmp"
struct Mods { struct Mods {
struct Mod** entries; struct Mod** entries;

View File

@ -373,7 +373,7 @@ int main(int argc, char *argv[]) {
#endif #endif
old_user_folder_handler(); legacy_folder_handler();
const char *userpath = gCLIOpts.savePath[0] ? gCLIOpts.savePath : sys_user_path(); const char *userpath = gCLIOpts.savePath[0] ? gCLIOpts.savePath : sys_user_path();
fs_init(userpath); fs_init(userpath);

View File

@ -7,7 +7,7 @@
/* platform-specific functions and whatnot */ /* platform-specific functions and whatnot */
#define SYS_MAX_PATH 4096 // FIXME: define this on different platforms #define SYS_MAX_PATH 4096
// crossplatform impls of misc stuff // crossplatform impls of misc stuff
char *sys_strdup(const char *src); char *sys_strdup(const char *src);

View File

@ -3,10 +3,15 @@
#include <vector> #include <vector>
#include <filesystem> #include <filesystem>
#if defined(_WIN32) || defined(_WIN64)
#include <windows.h>
#endif
extern "C" { extern "C" {
#include "platform.h" #include "platform.h"
#include "mods/mods_utils.h" // for str_ends_with #include "mods/mods_utils.h" // for str_ends_with
#include "mods/mod_cache.h" // for md5 hashing #include "mods/mod_cache.h" // for md5 hashing
#include "mods/mods.h"
#include "loading.h" #include "loading.h"
} }
@ -30,16 +35,26 @@ static struct VanillaMD5 sVanillaMD5[] = {
{ NULL, NULL }, { NULL, NULL },
}; };
static void copy_old_user_folder() { inline static void copy_old_user_folder() {
char* oldpath = (char*)sys_old_user_path(); std::string userPath = sys_user_path();
char* newpath = (char*)sys_user_path(); std::string oldPath = sys_old_user_path();
if (fs::exists(oldPath) && (fs::is_empty(userPath) || !fs::exists(userPath))) {
if (fs::exists(oldpath) && (fs::is_empty(newpath) || !fs::exists(newpath))) { fs::copy(oldPath, userPath, fs::copy_options::recursive);
fs::copy(oldpath, newpath);
gUserFolderCopied = true; gUserFolderCopied = true;
} }
} }
inline static void rename_tmp_folder() {
std::string userPath = sys_user_path();
std::string oldPath = userPath + "/tmp";
if (fs::exists(oldPath)) {
#if defined(_WIN32) || defined(_WIN64)
SetFileAttributesA(oldPath.c_str(), FILE_ATTRIBUTE_HIDDEN);
#endif
fs::rename(oldPath, userPath + "/" + TMP_DIRECTORY);
}
}
static bool is_rom_valid(const std::string romPath) { static bool is_rom_valid(const std::string romPath) {
u8 dataHash[16] = { 0 }; u8 dataHash[16] = { 0 };
mod_cache_md5(romPath.c_str(), dataHash); mod_cache_md5(romPath.c_str(), dataHash);
@ -83,8 +98,9 @@ inline static bool scan_path_for_rom(const char *dir) {
} }
extern "C" { extern "C" {
void old_user_folder_handler(void) { void legacy_folder_handler(void) {
copy_old_user_folder(); copy_old_user_folder();
if (gUserFolderCopied) { rename_tmp_folder(); }
} }
bool main_rom_handler(void) { bool main_rom_handler(void) {

View File

@ -4,7 +4,7 @@ extern bool gUserFolderCopied;
extern bool gRomIsValid; extern bool gRomIsValid;
extern char gRomFilename[]; extern char gRomFilename[];
void old_user_folder_handler(void); void legacy_folder_handler(void);
bool main_rom_handler(void); bool main_rom_handler(void);
void rom_on_drop_file(const char *path); void rom_on_drop_file(const char *path);