Skip to content

Commit

Permalink
FEXConfig: Add the ability to watch and configure global rootfs
Browse files Browse the repository at this point in the history
Global rootfs doesn't support a named rootfs (only local supports that).
So when it is a global rootfs option just give the full path to the
config path.

Just needs some special handling to ensure the full path is retained for
global paths.

A reimplementation of #4067 that doesn't hardcode paths and routes the
global data path through FEXCore.
  • Loading branch information
Sonicadvance1 committed Sep 18, 2024
1 parent e150c8e commit 67fcb37
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
46 changes: 33 additions & 13 deletions Source/Tools/FEXConfig/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,12 @@ static void ConfigInit(fextl::string ConfigFilename) {
RootFSModel::RootFSModel() {
INotifyFD = inotify_init1(IN_NONBLOCK | IN_CLOEXEC);

fextl::string RootFS = FEXCore::Config::GetDataDirectory() + "RootFS/";
FolderFD = inotify_add_watch(INotifyFD, RootFS.c_str(), IN_CREATE | IN_DELETE);
if (FolderFD != -1) {
fextl::string RootFS = FEXCore::Config::GetDataDirectory(false) + "RootFS/";
int LocalFolderWD = inotify_add_watch(INotifyFD, RootFS.c_str(), IN_CREATE | IN_DELETE);

RootFS = FEXCore::Config::GetDataDirectory(true) + "RootFS/";
int GlobalFolderWD = inotify_add_watch(INotifyFD, RootFS.c_str(), IN_CREATE | IN_DELETE);
if (INotifyFD != -1 && (LocalFolderWD != -1 || GlobalFolderWD != -1)) {
Thread = std::thread {&RootFSModel::INotifyThreadFunc, this};
} else {
qWarning() << "Could not set up inotify. RootFS folder won't be monitored for changes.";
Expand All @@ -214,20 +217,37 @@ void RootFSModel::Reload() {
beginResetModel();
removeRows(0, rowCount());

fextl::string RootFS = FEXCore::Config::GetDataDirectory() + "RootFS/";
std::vector<QString> NamedRootFS {};
for (auto& it : std::filesystem::directory_iterator(RootFS)) {
if (it.is_directory()) {
NamedRootFS.push_back(QString::fromStdString(it.path().filename()));
} else if (it.is_regular_file()) {
// If it is a regular file then we need to check if it is a valid archive
if (it.path().extension() == ".sqsh" && FEX::FormatCheck::IsSquashFS(fextl::string_from_path(it.path()))) {
NamedRootFS.push_back(QString::fromStdString(it.path().filename()));
} else if (it.path().extension() == ".ero" && FEX::FormatCheck::IsEroFS(fextl::string_from_path(it.path()))) {
NamedRootFS.push_back(QString::fromStdString(it.path().filename()));
for (auto Global : {false, true}) {
const fextl::string RootFS = FEXCore::Config::GetDataDirectory(Global) + "RootFS/";

if (!std::filesystem::exists(RootFS)) {
continue;
}

for (auto& it : std::filesystem::directory_iterator(RootFS)) {
std::string Path {};
if (Global) {
// If global then keep the full path.
Path = it.path();
} else {
// If local then only use the filename.
Path = it.path().filename();
}

if (it.is_directory()) {
NamedRootFS.push_back(QString::fromStdString(Path));
} else if (it.is_regular_file()) {
// If it is a regular file then we need to check if it is a valid archive
if (it.path().extension() == ".sqsh" && FEX::FormatCheck::IsSquashFS(fextl::string_from_path(it.path()))) {
NamedRootFS.push_back(QString::fromStdString(Path));
} else if (it.path().extension() == ".ero" && FEX::FormatCheck::IsEroFS(fextl::string_from_path(it.path()))) {
NamedRootFS.push_back(QString::fromStdString(Path));
}
}
}
}

std::sort(NamedRootFS.begin(), NamedRootFS.end(), [](const QString& a, const QString& b) { return QString::localeAwareCompare(a, b) < 0; });
for (auto& Entry : NamedRootFS) {
appendRow(new QStandardItem(Entry));
Expand Down
1 change: 0 additions & 1 deletion Source/Tools/FEXConfig/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class RootFSModel : public QStandardItemModel {
std::latch ExitRequest {1};

int INotifyFD;
int FolderFD;

void INotifyThreadFunc();

Expand Down

0 comments on commit 67fcb37

Please sign in to comment.