Skip to content

Commit

Permalink
Changed ArenaPath to ArenaPaths.
Browse files Browse the repository at this point in the history
Works best on Windows for now. Might add Linux and macOS Steam install paths later.
  • Loading branch information
afritz1 committed Jul 21, 2024
1 parent b7016cd commit f322f15
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 35 deletions.
88 changes: 59 additions & 29 deletions OpenTESArena/src/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,65 @@ namespace
}
};

bool TryMakeValidArenaExePath(const std::string &vfsFolderPath, std::string *outExePath, bool *outIsFloppyDiskVersion)
bool TryGetArenaAssetsDirectory(BufferView<const std::string> arenaPaths, const std::string &basePath, std::string *outDirectory, bool *outIsFloppyDiskVersion)
{
std::vector<std::string> validArenaPaths;
for (std::string path : arenaPaths)
{
if (path.empty())
{
continue;
}

if (Path::isRelative(path.c_str()))
{
path = basePath + path;
}

validArenaPaths.emplace_back(std::move(path));
}

// Check for CD version first.
const std::string &cdExeName = ExeData::CD_VERSION_EXE_FILENAME;
std::string cdExePath = vfsFolderPath + cdExeName;
if (File::exists(cdExePath.c_str()))
for (const std::string &path : validArenaPaths)
{
DebugLog("CD executable \"" + cdExeName + "\" found in \"" + vfsFolderPath + "\".");
*outExePath = std::move(cdExePath);
const std::filesystem::path fsPath(path);
std::error_code dummy;
if (!std::filesystem::exists(fsPath, dummy) || !std::filesystem::is_directory(fsPath, dummy))
{
continue;
}

const std::string &cdExeName = ExeData::CD_VERSION_EXE_FILENAME;
const std::filesystem::path cdExePath = fsPath / cdExeName;
if (!std::filesystem::exists(cdExePath, dummy) || !std::filesystem::is_regular_file(cdExePath, dummy))
{
continue;
}

DebugLog("CD version assets found in \"" + path + "\".");
*outDirectory = path;
*outIsFloppyDiskVersion = false;
return true;
}

const std::string &floppyDiskExeName = ExeData::FLOPPY_VERSION_EXE_FILENAME;
std::string floppyDiskExePath = vfsFolderPath + floppyDiskExeName;
if (File::exists(floppyDiskExePath.c_str()))
for (const std::string &path : validArenaPaths)
{
DebugLog("Floppy disk executable \"" + floppyDiskExeName + "\" found in \"" + vfsFolderPath + "\".");
*outExePath = std::move(floppyDiskExePath);
const std::filesystem::path fsPath(path);
std::error_code dummy;
if (!std::filesystem::exists(fsPath, dummy) || !std::filesystem::is_directory(fsPath, dummy))
{
continue;
}

const std::string &floppyDiskExeName = ExeData::FLOPPY_VERSION_EXE_FILENAME;
const std::filesystem::path floppyDiskExePath = fsPath / floppyDiskExeName;
if (!std::filesystem::exists(floppyDiskExePath, dummy) || !std::filesystem::is_regular_file(floppyDiskExePath, dummy))
{
continue;
}

DebugLog("Floppy disk version assets found in \"" + path + "\".");
*outDirectory = path;
*outIsFloppyDiskVersion = true;
return true;
}
Expand Down Expand Up @@ -180,29 +220,19 @@ bool Game::init()
const std::string optionsPath = Platform::getOptionsPath();
this->initOptions(basePath, optionsPath);

const std::string &arenaPath = this->options.getMisc_ArenaPath();
DebugLog("Using ArenaPath \"" + arenaPath + "\".");

// Initialize virtual file system using the Arena path in the options file.
const bool arenaPathIsRelative = Path::isRelative(arenaPath.c_str());
const std::string vfsFolderPath = String::addTrailingSlashIfMissing((arenaPathIsRelative ? basePath : "") + arenaPath);
if (!Directory::exists(vfsFolderPath.c_str()))
{
DebugLogError("Data files directory \"" + vfsFolderPath + "\" not found. Is your ArenaPath correct?");
return false;
}

VFS::Manager::get().initialize(std::string(vfsFolderPath));

// Determine which game version the data path is pointing to.
std::string arenaExePath;
// Search ArenaPaths directories for a valid Arena install.
const std::string &arenaPathsString = this->options.getMisc_ArenaPaths();
const Buffer<std::string> arenaPaths = String::split(arenaPathsString, ',');
std::string arenaPath;
bool isFloppyDiskVersion;
if (!TryMakeValidArenaExePath(vfsFolderPath, &arenaExePath, &isFloppyDiskVersion))
if (!TryGetArenaAssetsDirectory(arenaPaths, basePath, &arenaPath, &isFloppyDiskVersion))
{
DebugLogError("\"" + vfsFolderPath + "\" does not contain an Arena executable.");
DebugLogError("Couldn't find Arena executable in these directories: " + arenaPathsString);
return false;
}

VFS::Manager::get().initialize(std::string(arenaPath));

// Initialize audio manager.
const bool midiPathIsRelative = Path::isRelative(this->options.getAudio_MidiConfig().c_str());
const std::string midiFilePath = (midiPathIsRelative ? basePath : "") + this->options.getAudio_MidiConfig();
Expand Down
2 changes: 1 addition & 1 deletion OpenTESArena/src/Game/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace

const std::vector<std::pair<std::string, OptionType>> MiscMappings =
{
{ "ArenaPath", OptionType::String },
{ "ArenaPaths", OptionType::String },
{ "ArenaSavesPath", OptionType::String },
{ "GhostMode", OptionType::Bool },
{ "ProfilerLevel", OptionType::Int },
Expand Down
2 changes: 1 addition & 1 deletion OpenTESArena/src/Game/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void set##section##_##name(const std::string &value) \
OPTION_DOUBLE(Input, VerticalSensitivity)
OPTION_DOUBLE(Input, CameraPitchLimit)

OPTION_STRING(Misc, ArenaPath)
OPTION_STRING(Misc, ArenaPaths)
OPTION_STRING(Misc, ArenaSavesPath)
OPTION_BOOL(Misc, GhostMode)
OPTION_INT(Misc, ProfilerLevel)
Expand Down
8 changes: 4 additions & 4 deletions options/options-default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ VerticalSensitivity=5.0
CameraPitchLimit=85.0

[Misc]
# Change "ArenaPath" to your desired path. In the future, this should be
# set by a wizard instead.
ArenaPath=data/ARENA/
# Comma-separated paths the engine will use to search your computer for ACD.EXE
# and A.EXE, preferring the CD version.
ArenaPaths=data/ARENACD,data/ARENA,C:/Program Files (x86)/Steam/steamapps/common/The Elder Scrolls Arena/ARENA,D:/SteamLibrary/steamapps/common/The Elder Scrolls Arena/ARENA

# Change "ArenaSavesPath" to your classic saves folder (if any).
ArenaSavesPath=data/ArenaSaves/
ArenaSavesPath=data/ArenaSaves

# Determines whether the player ignores collision and can fly around.
GhostMode=false
Expand Down

0 comments on commit f322f15

Please sign in to comment.