Supermodel icon indicating copy to clipboard operation
Supermodel copied to clipboard

Increase configurability for `~/.config` and `~/.local` paths

Open msanft opened this issue 10 months ago • 0 comments

Hey there!

The PR https://github.com/NixOS/nixpkgs/pull/302417 tries to package Supermodel for NixOS. Nix Packages have to strictly live in one path only, which is why programs relying on external directories (e.g. ~/.local/share/supermodel/Assets/ and ~/.config/supermodel/Config/Supermodel.ini for Supermodel) are usually wrapped with command line arguments specifying different paths for such values. This does not seem to be possible with Supermodel currently.

Would it be possible to make the path to the ~/.local/share/supermodel and ~/.config/supermodel/ directories configurable via the command line?

Thanks in advance!

msanft avatar Apr 08 '24 08:04 msanft

Src/OSD/FileSystemPath.h /*

  • FileSystemPaths.h
  • Header file for OS-dependent Supermodel files locations. */

#ifndef INCLUDED_FILESYSTEMPATH_H #define INCLUDED_FILESYSTEMPATH_H

#include #include #include <unistd.h> #include <pwd.h> #include <sys/types.h>

/* namespace FileSystemPath { enum PathType { Analysis, Config, Log, NVRAM, Saves, Screenshots, Assets }; // Filesystem path types bool PathExists(std::string fileSystemPath); // Checks if a directory exists (returns true if exists, false if it doesn't) std::string GetPath(PathType pathType); // Generates a path to be used by Supermodel files } */

namespace FileSystemPath { enum PathType { Analysis, Config, Log, NVRAM, Saves, Screenshots, Assets }; // Filesystem path types bool PathExists(const std::string& fileSystemPath); // Checks if a directory exists (returns true if exists, false if it doesn't) std::string GetPath(PathType pathType); // Generates a path to be used by Supermodel files }

#endif // INCLUDED_FILESYSTEMPATH_H

ioamero avatar May 05 '24 03:05 ioamero

Src/OSD/Unix/FileSystemPath.cpp

** You should have received a copy of the GNU General Public License along ** with Supermodel. If not, see http://www.gnu.org/licenses/. **/ #include "FileSystemPath.h" #include "Util/Format.h" #include #include

namespace FileSystemPath { namespace fs = std::filesystem;

bool PathExists(const std::string& fileSystemPath)
{
    return fs::exists(fileSystemPath) && fs::is_directory(fileSystemPath);
}

std::string GetPath(PathType pathType)
{
    std::string strPathType = "";

    // Resolve pathType to string for later use
    switch (pathType)
    {
        case Analysis:
            strPathType = "Analysis/";
            break;
        case Config:
            strPathType = "Config/";
            break;
        case Log:
            strPathType = "Log/";
            break;
        case NVRAM:
            strPathType = "NVRAM/";
            break;
        case Saves:
            strPathType = "Saves/";
            break;
        case Screenshots:
            strPathType = "Screenshots/";
            break;
        case Assets:
            strPathType = "Assets/";
            break;
    }

    // Set the base path to /opt/emulators/share
    fs::path basePath("/opt/emulators/share/supermodel");

    // Create the final path
    fs::path finalPath = (pathType == Config) ? basePath / "Config/" : basePath / strPathType;

    // If directory doesn't exist, create it
    if (!FileSystemPath::PathExists(finalPath))
    {
        fs::create_directories(finalPath);
    }

    return finalPath.string();
}

}

ioamero avatar May 05 '24 03:05 ioamero