Skip to content

Commit

Permalink
chore: add marker file in User folder
Browse files Browse the repository at this point in the history
will be useful for knowing if the launcher should nuke the User folder when we transition to mainline
  • Loading branch information
NikhilNarayana committed Sep 22, 2023
1 parent 0d841fd commit c656657
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 190 deletions.
5 changes: 3 additions & 2 deletions Source/Core/Common/CommonPaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
// loading a "local" User folder that I don't want to screw with.
#define USERDATA_DIR "Contents/Resources/User"

// `DOLPHIN_DATA_DIR` is commented out so that any place in
// the build that uses it (for macOS) produces an error, as this shouldn't collide
// `DOLPHIN_DATA_DIR` is commented out so that any place in
// the build that uses it (for macOS) produces an error, as this shouldn't collide
// with a mainline installation.
// #define DOLPHIN_DATA_DIR "Library/Application Support/Dolphin"
#elif defined ANDROID
Expand Down Expand Up @@ -146,3 +146,4 @@

// Slippi
#define USER_JSON "user.json"
#define VERSION_FILE "ishiiruka"
1 change: 1 addition & 0 deletions Source/Core/Common/FileUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ static void RebuildUserDirectories(unsigned int dir_index)
s_user_paths[F_GCSRAM_IDX] = s_user_paths[D_GCUSER_IDX] + GC_SRAM;
s_user_paths[F_WIISDCARD_IDX] = s_user_paths[D_WIIROOT_IDX] + DIR_SEP WII_SDCARD;
s_user_paths[F_USERJSON_IDX] = s_user_paths[D_SLIPPI_IDX] + USER_JSON;
s_user_paths[F_VERSION_IDX] = s_user_paths[D_USER_IDX] + VERSION_FILE;

s_user_paths[D_MEMORYWATCHER_IDX] = s_user_paths[D_USER_IDX] + MEMORYWATCHER_DIR DIR_SEP;
s_user_paths[F_MEMORYWATCHERLOCATIONS_IDX] = s_user_paths[D_MEMORYWATCHER_IDX] + MEMORYWATCHER_LOCATIONS;
Expand Down
110 changes: 53 additions & 57 deletions Source/Core/Common/FileUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ enum
{
D_USER_IDX,
D_GCUSER_IDX,
D_WIIROOT_IDX, // always points to User/Wii or global user-configured directory
D_SESSION_WIIROOT_IDX, // may point to minimal temporary directory for determinism
D_CONFIG_IDX, // global settings
D_GAMESETTINGS_IDX, // user-specified settings which override both the global and the default settings (per game)
D_WIIROOT_IDX, // always points to User/Wii or global user-configured directory
D_SESSION_WIIROOT_IDX, // may point to minimal temporary directory for determinism
D_CONFIG_IDX, // global settings
D_GAMESETTINGS_IDX, // user-specified settings which override both the global and the default settings (per game)
D_MAPS_IDX,
D_CACHE_IDX,
D_SHADERCACHE_IDX,
Expand Down Expand Up @@ -61,6 +61,7 @@ enum
F_MEMORYWATCHERSOCKET_IDX,
F_WIISDCARD_IDX,
F_USERJSON_IDX,
F_VERSION_IDX,
NUM_PATH_INDICES
};

Expand All @@ -70,57 +71,57 @@ namespace File
struct FSTEntry
{
bool isDirectory;
u64 size; // File length, or for directories, recursive count of children
std::string physicalName; // Name on disk
std::string virtualName; // Name in FST names table
u64 size; // File length, or for directories, recursive count of children
std::string physicalName; // Name on disk
std::string virtualName; // Name in FST names table
std::vector<FSTEntry> children;
};

// Returns true if file filename exists
bool Exists(const std::string& filename);
bool Exists(const std::string &filename);

// Returns true if filename is a directory
bool IsDirectory(const std::string& filename);
bool IsDirectory(const std::string &filename);

// Returns the size of filename (64bit)
u64 GetSize(const std::string& filename);
u64 GetSize(const std::string &filename);

// Overloaded GetSize, accepts file descriptor
u64 GetSize(const int fd);

// Overloaded GetSize, accepts FILE*
u64 GetSize(FILE* f);
u64 GetSize(FILE *f);

// Returns true if successful, or path already exists.
bool CreateDir(const std::string& filename);
bool CreateDir(const std::string &filename);

// Creates the full path of fullPath returns true on success
bool CreateFullPath(const std::string& fullPath);
bool CreateFullPath(const std::string &fullPath);

// Deletes a given filename, return true on success
// Doesn't supports deleting a directory
bool Delete(const std::string& filename);
bool Delete(const std::string &filename);

// Deletes a directory filename, returns true on success
bool DeleteDir(const std::string& filename);
bool DeleteDir(const std::string &filename);

// renames file srcFilename to destFilename, returns true on success
bool Rename(const std::string& srcFilename, const std::string& destFilename);
bool Rename(const std::string &srcFilename, const std::string &destFilename);

// ditto, but syncs the source file and, on Unix, syncs the directories after rename
bool RenameSync(const std::string& srcFilename, const std::string& destFilename);
bool RenameSync(const std::string &srcFilename, const std::string &destFilename);

// copies file srcFilename to destFilename, returns true on success
bool Copy(const std::string& srcFilename, const std::string& destFilename);
bool Copy(const std::string &srcFilename, const std::string &destFilename);

// creates an empty file filename, returns true on success
bool CreateEmptyFile(const std::string& filename);
bool CreateEmptyFile(const std::string &filename);

// Recursive or non-recursive list of files and directories under directory.
FSTEntry ScanDirectoryTree(const std::string& directory, bool recursive);
FSTEntry ScanDirectoryTree(const std::string &directory, bool recursive);

// deletes the given directory and anything under it. Returns true on success.
bool DeleteDirRecursively(const std::string& directory);
bool DeleteDirRecursively(const std::string &directory);

// Returns the current directory
std::string GetCurrentDir();
Expand All @@ -129,27 +130,27 @@ std::string GetCurrentDir();
u64 GetFileModTime(const std::string &path);

// Create directory and copy contents (does not overwrite existing files)
void CopyDir(const std::string& source_path, const std::string& dest_path);
void CopyDir(const std::string &source_path, const std::string &dest_path);

// Set the current directory to given directory
bool SetCurrentDir(const std::string& directory);
bool SetCurrentDir(const std::string &directory);

// Creates and returns the path to a new temporary directory.
std::string CreateTempDir();

// Get a filename that can hopefully be atomically renamed to the given path.
std::string GetTempFilenameForAtomicWrite(const std::string& path);
std::string GetTempFilenameForAtomicWrite(const std::string &path);

// Gets a set user directory path
// Don't call prior to setting the base user directory
const std::string& GetUserPath(unsigned int dir_index);
const std::string &GetUserPath(unsigned int dir_index);

// Sets a user directory path
// Rebuilds internal directory structure to compensate for the new directory
void SetUserPath(unsigned int dir_index, const std::string& path);
void SetUserPath(unsigned int dir_index, const std::string &path);

// probably doesn't belong here
std::string GetThemeDir(const std::string& theme_name);
std::string GetThemeDir(const std::string &theme_name);

// Gets the path where a Slippi user.json file lives.
std::string GetSlippiUserJSONPath();
Expand All @@ -162,37 +163,36 @@ std::string GetBundleDirectory();
std::string GetApplicationSupportDirectory();
#endif

std::string& GetExeDirectory();
std::string &GetExeDirectory();

std::string GetHomeDirectory();

bool WriteStringToFile(const std::string& str, const std::string& filename);
bool ReadFileToString(const std::string& filename, std::string& str);
bool WriteStringToFile(const std::string &str, const std::string &filename);
bool ReadFileToString(const std::string &filename, std::string &str);

// simple wrapper for cstdlib file functions to
// hopefully will make error checking easier
// and make forgetting an fclose() harder
class IOFile : public NonCopyable
{
public:
public:
IOFile();
IOFile(std::FILE* file);
IOFile(const std::string& filename, const char openmode[]);
IOFile(const std::string & filename, const char openmode[], int shflag);
IOFile(std::FILE *file);
IOFile(const std::string &filename, const char openmode[]);
IOFile(const std::string &filename, const char openmode[], int shflag);

~IOFile();

IOFile(IOFile&& other) noexcept;
IOFile& operator=(IOFile&& other) noexcept;
IOFile(IOFile &&other) noexcept;
IOFile &operator=(IOFile &&other) noexcept;

void Swap(IOFile& other) noexcept;
void Swap(IOFile &other) noexcept;

bool Open(const std::string& filename, const char openmode[]);
bool OpenShared(const std::string & filename, const char openmode[], int shflag);
bool Open(const std::string &filename, const char openmode[]);
bool OpenShared(const std::string &filename, const char openmode[], int shflag);
bool Close();

template <typename T>
bool ReadArray(T* data, size_t length, size_t* pReadBytes = nullptr)
template <typename T> bool ReadArray(T *data, size_t length, size_t *pReadBytes = nullptr)
{
size_t read_bytes = 0;
if (!IsOpen() || length != (read_bytes = std::fread(data, sizeof(T), length, m_file)))
Expand All @@ -204,33 +204,29 @@ class IOFile : public NonCopyable
return m_good;
}

template <typename T>
bool WriteArray(const T* data, size_t length)
template <typename T> bool WriteArray(const T *data, size_t length)
{
if (!IsOpen() || length != std::fwrite(data, sizeof(T), length, m_file))
m_good = false;

return m_good;
}

bool ReadBytes(void* data, size_t length)
{
return ReadArray(reinterpret_cast<char*>(data), length);
}
bool ReadBytes(void *data, size_t length) { return ReadArray(reinterpret_cast<char *>(data), length); }

bool WriteBytes(const void* data, size_t length)
bool WriteBytes(const void *data, size_t length)
{
return WriteArray(reinterpret_cast<const char*>(data), length);
return WriteArray(reinterpret_cast<const char *>(data), length);
}

bool IsOpen() const { return nullptr != m_file; }
// m_good is set to false when a read, write or other function fails
bool IsGood() const { return m_good; }
explicit operator bool() const { return IsGood() && IsOpen(); }
std::FILE* ReleaseHandle();
std::FILE *ReleaseHandle();

std::FILE* GetHandle() { return m_file; }
void SetHandle(std::FILE* file);
std::FILE *GetHandle() { return m_file; }
void SetHandle(std::FILE *file);

bool Seek(s64 off, int origin);
u64 Tell() const;
Expand All @@ -244,16 +240,16 @@ class IOFile : public NonCopyable
m_good = true;
std::clearerr(m_file);
}
private:
std::FILE* m_file;

private:
std::FILE *m_file;
bool m_good;
};

} // namespace
} // namespace File

// To deal with Windows being dumb at unicode:
template <typename T>
void OpenFStream(T& fstream, const std::string& filename, std::ios_base::openmode openmode)
template <typename T> void OpenFStream(T &fstream, const std::string &filename, std::ios_base::openmode openmode)
{
#ifdef _WIN32
fstream.open(UTF8ToTStr(filename).c_str(), openmode);
Expand Down
5 changes: 4 additions & 1 deletion Source/Core/DolphinWX/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ bool DolphinApp::OnInit()
RegisterMsgAlertHandler(&wxMsgAlert);
RegisterStringTranslator(&wxStringTranslator);

// Don't use wxWidgets fatal exception handling on macOS as it obscures the root cause.
// Don't use wxWidgets fatal exception handling on macOS as it obscures the root cause.
#ifndef __APPLE__
#if wxUSE_ON_FATAL_EXCEPTION
wxHandleFatalExceptions(true);
Expand All @@ -133,6 +133,9 @@ bool DolphinApp::OnInit()

UICommon::SetUserDirectory(m_user_path.ToStdString());
UICommon::CreateDirectories();
// create the version marker file so we know that the user folder is from ishiiruka
auto marker_file_path = File::GetUserPath(F_VERSION_IDX);
File::WriteStringToFile("", marker_file_path);
InitLanguageSupport(); // The language setting is loaded from the user directory
UICommon::Init();

Expand Down
Loading

0 comments on commit c656657

Please sign in to comment.