@ -2,10 +2,11 @@
// SPDX-License-Identifier: GPL-3.0-or-later
# include <filesystem>
# include "fs.h"
# include "common/ fs/path_util .h"
# include "common/fs/ryujinx_compat.h"
# include "common/fs/symlink.h"
# include "frontend_common/data_manager.h"
# include "fs.h"
# include "qt_common/abstract/frontend.h"
# include "qt_common/qt_string_lookup.h"
@ -56,6 +57,9 @@ bool CheckUnlink(const fs::path &eden_dir, const fs::path &ryu_dir)
orig = eden_dir ;
}
linked . make_preferred ( ) ;
orig . make_preferred ( ) ;
// first cleanup the symlink/junction,
try {
// NB: do NOT use remove_all, as Windows treats this as a remove_all to the target,
@ -84,17 +88,53 @@ bool CheckUnlink(const fs::path &eden_dir, const fs::path &ryu_dir)
return true ;
}
u64 GetRyujinxSaveID ( const u64 & program_id )
const fs : : path GetRyujinxSavePath ( const fs : : path & path_hint , const u64 & program_id )
{
auto path = Common : : FS : : GetKvdbPath ( ) ;
auto ryu_path = path_hint ;
auto kvdb_path = Common : : FS : : GetKvdbPath ( ryu_path ) ;
if ( ! fs : : exists ( kvdb_path ) ) {
using namespace QtCommon : : Frontend ;
auto res = Warning (
tr ( " Could not find Ryujinx installation " ) ,
tr ( " Could not find a valid Ryujinx installation. This may typically occur if you are "
" using Ryujinx in portable mode. \n \n Would you like to manually select a portable "
" folder to use? " ) , StandardButton : : Yes | StandardButton : : No ) ;
if ( res = = StandardButton : : Yes ) {
auto selected_path = GetExistingDirectory ( tr ( " Ryujinx Portable Location " ) , QDir : : homePath ( ) ) . toStdString ( ) ;
if ( selected_path . empty ( ) )
return fs : : path { } ;
ryu_path = selected_path ;
// In case the user selects the actual ryujinx installation dir INSTEAD OF
// the portable dir
if ( fs : : exists ( ryu_path / " portable " ) ) {
ryu_path = ryu_path / " portable " ;
}
kvdb_path = Common : : FS : : GetKvdbPath ( ryu_path ) ;
if ( ! fs : : exists ( kvdb_path ) ) {
QtCommon : : Frontend : : Critical (
tr ( " Not a valid Ryujinx directory " ) ,
tr ( " The specified directory does not contain valid Ryujinx data. " ) ) ;
return fs : : path { } ;
}
} else {
return fs : : path { } ;
}
}
std : : vector < Common : : FS : : IMEN > imens ;
Common : : FS : : IMENReadResult res = Common : : FS : : ReadKvdb ( path , imens ) ;
Common : : FS : : IMENReadResult res = Common : : FS : : ReadKvdb ( kvdb_ path, imens ) ;
if ( res = = Common : : FS : : IMENReadResult : : Success ) {
// TODO: this can probably be done with std::find_if but I'm lazy
for ( const Common : : FS : : IMEN & imen : imens ) {
if ( imen . title_id = = program_id )
return imen . save_id ;
return Common : : FS : : GetRyuSavePath ( ryu_path , imen . save_id ) ;
}
QtCommon : : Frontend : : Critical (
@ -107,24 +147,7 @@ u64 GetRyujinxSaveID(const u64 &program_id)
QtCommon : : Frontend : : Critical ( tr ( " Could not find Ryujinx save data " ) , caption ) ;
}
return - 1 ;
}
std : : optional < std : : pair < fs : : path , fs : : path > > GetEmuPaths (
const u64 program_id , const u64 save_id , const std : : string & user_id )
{
fs : : path ryu_dir = Common : : FS : : GetRyuSavePath ( save_id ) ;
if ( user_id . empty ( ) )
return std : : nullopt ;
std : : string hex_program = fmt : : format ( " {:016X} " , program_id ) ;
fs : : path eden_dir
= FrontendCommon : : DataManager : : GetDataDir ( FrontendCommon : : DataManager : : DataDir : : Saves ,
user_id )
/ hex_program ;
return std : : make_pair ( eden_dir , ryu_dir ) ;
return fs : : path { } ;
}
} // namespace QtCommon::FS