Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 31d7335

Browse files
authored
Merge pull request #1818 from reicast/scribam-linux-homedir
CL: --portable and nodisk support
2 parents 2eb6522 + 27deba9 commit 31d7335

File tree

10 files changed

+95
-79
lines changed

10 files changed

+95
-79
lines changed

libswirl/android/Android.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ JNIEXPORT jstring JNICALL Java_com_reicast_emulator_emu_JNIdc_initEnvironment(JN
229229
const char* path = homeDirectory != NULL ? env->GetStringUTFChars(homeDirectory, 0) : "";
230230
set_user_config_dir(path);
231231
set_user_data_dir(path);
232-
printf("Config dir is: %s\n", get_writable_config_path("").c_str());
233-
printf("Data dir is: %s\n", get_writable_data_path("").c_str());
232+
234233
if (homeDirectory != NULL)
235234
env->ReleaseStringUTFChars(homeDirectory, path);
236235

libswirl/cfg/cl.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ int showhelp(wchar** arg,int cl)
107107
printf("\nAvailable commands :\n");
108108

109109
printf("-config section:key=value [, ..]: add a virtual config value\n Virtual config values won't be saved to the .cfg file\n unless a different value is written to em\nNote :\n You can specify many settings in the xx:yy=zz , gg:hh=jj , ...\n format.The spaces between the values and ',' are needed.\n");
110+
printf("-portable: look for data and discs in the current directory\n");
110111
printf("\n-help: show help info\n");
111112

112113
return 0;
@@ -130,6 +131,16 @@ bool ParseCommandLine(int argc,wchar* argv[])
130131
cl-=as;
131132
arg+=as;
132133
}
134+
else if (stricmp(*arg,"-portable")==0 || stricmp(*arg,"--portable")==0)
135+
{
136+
clear_dirs();
137+
138+
//portable mode uses relative paths to CWD
139+
set_user_config_dir(".");
140+
set_user_data_dir(".");
141+
add_system_config_dir(".");
142+
add_system_data_dir(".");
143+
}
133144
else
134145
{
135146
char* extension = strrchr(*arg, '.');
@@ -148,6 +159,11 @@ bool ParseCommandLine(int argc,wchar* argv[])
148159
cfgSetVirtual("config", "reios.enabled", "1");
149160
cfgSetVirtual("reios", "ElfFile", *arg);
150161
}
162+
else if (stricmp(*arg, "nodisk") == 0)
163+
{
164+
printf("Starting without cd image\n");
165+
cfgSetVirtual("config", "image", "nodisk");
166+
}
151167
else
152168
{
153169
#if DC_PLATFORM == DC_PLATFORM_NAOMI || DC_PLATFORM == DC_PLATFORM_ATOMISWAVE

libswirl/gui/gui.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,8 @@ struct ReicastUI_impl : GUI {
731731

732732
virtualDreamcast->Init();
733733

734-
int rc = virtualDreamcast->StartGame(path.empty() ? NULL : path.c_str());
734+
int rc = virtualDreamcast->StartGame(path);
735+
735736
if (rc != 0)
736737
{
737738
gui_state = Main;
@@ -910,11 +911,10 @@ struct ReicastUI_impl : GUI {
910911
}
911912

912913
#if DC_PLATFORM == DC_PLATFORM_DREAMCAST
913-
ImGui::PushID("bios");
914+
ImGui::PushID("nodisk");
914915
if (ImGui::Selectable("Dreamcast BIOS"))
915916
{
916-
cfgSetVirtual("config", "image", "");
917-
if (gui_start_game(""))
917+
if (gui_start_game("nodisk"))
918918
gui_state = Closed;
919919
}
920920
ImGui::PopID();

libswirl/libswirl.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ int GetFile(char* szFileName)
115115
{
116116
cfgLoadStr("config", "image", szFileName, "");
117117

118-
return szFileName[0] != '\0' ? 1 : 0;
118+
return stricmp(szFileName, "nodisk") != 0;
119119
}
120120

121121

@@ -615,6 +615,9 @@ int reicast_init(int argc, char* argv[])
615615
{
616616
return 69;
617617
}
618+
printf("Config dir is: %s\n", get_writable_config_path("/").c_str());
619+
printf("Data dir is: %s\n", get_writable_data_path("/").c_str());
620+
618621
InitSettings();
619622
bool showOnboarding = false;
620623
if (!cfgOpen())
@@ -807,10 +810,9 @@ struct Dreamcast_impl : VirtualDreamcast {
807810
sh4_cpu->aica_ram.Zero();
808811
}
809812

810-
int StartGame(const char* path)
813+
int StartGame(const string& path)
811814
{
812-
if (path != NULL)
813-
cfgSetVirtual("config", "image", path);
815+
cfgSetVirtual("config", "image", path.c_str());
814816

815817
if (settings.bios.UseReios || !LoadRomFiles(get_readonly_data_path(DATA_PATH)))
816818
{

libswirl/libswirl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct VirtualDreamcast {
1919
virtual void Resume() = 0;
2020
virtual bool Init() = 0;
2121
virtual void Term() = 0;
22-
virtual int StartGame(const char* path) = 0;
22+
virtual int StartGame(const string& path) = 0;
2323
virtual void RequestReset() = 0;
2424
virtual bool HandleFault(unat addr, rei_host_context_t* ctx) = 0;
2525
virtual ~VirtualDreamcast() { }

libswirl/linux-dist/main.cpp

Lines changed: 57 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <sys/param.h>
1919
#include <sys/mman.h>
2020
#include <sys/time.h>
21+
#include <sys/stat.h>
2122
#include "hw/sh4/dyna/blockmanager.h"
2223
#include "hw/maple/maple_cfg.h"
2324
#include <unistd.h>
@@ -42,10 +43,6 @@
4243
#include "sdl/sdl.h"
4344
#endif
4445

45-
#if defined(USES_HOMEDIR)
46-
#include <sys/stat.h>
47-
#endif
48-
4946
#if defined(USE_EVDEV)
5047
#include "linux-dist/evdev.h"
5148
#endif
@@ -237,83 +234,79 @@ void common_linux_setup();
237234

238235
string find_user_config_dir()
239236
{
240-
#ifdef USES_HOMEDIR
241-
struct stat info;
242-
string home = "";
243-
if(getenv("HOME") != NULL)
244-
{
245-
// Support for the legacy config dir at "$HOME/.reicast"
246-
string legacy_home = (string)getenv("HOME") + "/.reicast";
247-
if((stat(legacy_home.c_str(), &info) == 0) && (info.st_mode & S_IFDIR))
248-
{
249-
// "$HOME/.reicast" already exists, let's use it!
250-
return legacy_home;
251-
}
252-
253-
/* If $XDG_CONFIG_HOME is not set, we're supposed to use "$HOME/.config" instead.
254-
* Consult the XDG Base Directory Specification for details:
255-
* http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables
256-
*/
257-
home = (string)getenv("HOME") + "/.config/reicast";
258-
}
259-
if(getenv("XDG_CONFIG_HOME") != NULL)
237+
struct stat info;
238+
string home = "";
239+
if(getenv("HOME") != NULL)
240+
{
241+
// Support for the legacy config dir at "$HOME/.reicast"
242+
string legacy_home = (string)getenv("HOME") + "/.reicast";
243+
if((stat(legacy_home.c_str(), &info) == 0) && (info.st_mode & S_IFDIR))
260244
{
261-
// If XDG_CONFIG_HOME is set explicitly, we'll use that instead of $HOME/.config
262-
home = (string)getenv("XDG_CONFIG_HOME") + "/reicast";
245+
// "$HOME/.reicast" already exists, let's use it!
246+
return legacy_home;
263247
}
264248

265-
if(!home.empty())
249+
/* If $XDG_CONFIG_HOME is not set, we're supposed to use "$HOME/.config" instead.
250+
* Consult the XDG Base Directory Specification for details:
251+
* http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables
252+
*/
253+
home = (string)getenv("HOME") + "/.config/reicast";
254+
}
255+
if(getenv("XDG_CONFIG_HOME") != NULL)
256+
{
257+
// If XDG_CONFIG_HOME is set explicitly, we'll use that instead of $HOME/.config
258+
home = (string)getenv("XDG_CONFIG_HOME") + "/reicast";
259+
}
260+
261+
if(!home.empty())
262+
{
263+
if((stat(home.c_str(), &info) != 0) || !(info.st_mode & S_IFDIR))
266264
{
267-
if((stat(home.c_str(), &info) != 0) || !(info.st_mode & S_IFDIR))
268-
{
269-
// If the directory doesn't exist yet, create it!
270-
mkdir(home.c_str(), 0755);
271-
}
272-
return home;
265+
// If the directory doesn't exist yet, create it!
266+
mkdir(home.c_str(), 0755);
273267
}
274-
#endif
268+
return home;
269+
}
275270

276271
// Unable to detect config dir, use the current folder
277272
return ".";
278273
}
279274

280275
string find_user_data_dir()
281276
{
282-
#ifdef USES_HOMEDIR
283-
struct stat info;
284-
string data = "";
285-
if(getenv("HOME") != NULL)
286-
{
287-
// Support for the legacy config dir at "$HOME/.reicast"
288-
string legacy_data = (string)getenv("HOME") + "/.reicast";
289-
if((stat(legacy_data.c_str(), &info) == 0) && (info.st_mode & S_IFDIR))
290-
{
291-
// "$HOME/.reicast" already exists, let's use it!
292-
return legacy_data;
293-
}
294-
295-
/* If $XDG_DATA_HOME is not set, we're supposed to use "$HOME/.local/share" instead.
296-
* Consult the XDG Base Directory Specification for details:
297-
* http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables
298-
*/
299-
data = (string)getenv("HOME") + "/.local/share/reicast";
300-
}
301-
if(getenv("XDG_DATA_HOME") != NULL)
277+
struct stat info;
278+
string data = "";
279+
if(getenv("HOME") != NULL)
280+
{
281+
// Support for the legacy config dir at "$HOME/.reicast"
282+
string legacy_data = (string)getenv("HOME") + "/.reicast";
283+
if((stat(legacy_data.c_str(), &info) == 0) && (info.st_mode & S_IFDIR))
302284
{
303-
// If XDG_DATA_HOME is set explicitly, we'll use that instead of $HOME/.config
304-
data = (string)getenv("XDG_DATA_HOME") + "/reicast";
285+
// "$HOME/.reicast" already exists, let's use it!
286+
return legacy_data;
305287
}
306288

307-
if(!data.empty())
289+
/* If $XDG_DATA_HOME is not set, we're supposed to use "$HOME/.local/share" instead.
290+
* Consult the XDG Base Directory Specification for details:
291+
* http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html#variables
292+
*/
293+
data = (string)getenv("HOME") + "/.local/share/reicast";
294+
}
295+
if(getenv("XDG_DATA_HOME") != NULL)
296+
{
297+
// If XDG_DATA_HOME is set explicitly, we'll use that instead of $HOME/.config
298+
data = (string)getenv("XDG_DATA_HOME") + "/reicast";
299+
}
300+
301+
if(!data.empty())
302+
{
303+
if((stat(data.c_str(), &info) != 0) || !(info.st_mode & S_IFDIR))
308304
{
309-
if((stat(data.c_str(), &info) != 0) || !(info.st_mode & S_IFDIR))
310-
{
311-
// If the directory doesn't exist yet, create it!
312-
mkdir(data.c_str(), 0755);
313-
}
314-
return data;
305+
// If the directory doesn't exist yet, create it!
306+
mkdir(data.c_str(), 0755);
315307
}
316-
#endif
308+
return data;
309+
}
317310

318311
// Unable to detect config dir, use the current folder
319312
return ".";
@@ -439,8 +432,6 @@ int main(int argc, wchar* argv[])
439432
add_system_data_dir(dirs[i]);
440433
}
441434
add_system_data_dir(find_user_data_dir());
442-
printf("Config dir is: %s\n", get_writable_config_path("/").c_str());
443-
printf("Data dir is: %s\n", get_writable_data_path("/").c_str());
444435

445436
#if defined(USE_SDL)
446437
if (SDL_Init(0) != 0)

libswirl/stdclass.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ void add_system_data_dir(const string& dir)
5858
system_data_dirs.push_back(dir);
5959
}
6060

61+
void clear_dirs()
62+
{
63+
system_config_dirs.clear();
64+
system_data_dirs.clear();
65+
user_data_dir = "";
66+
user_config_dir = "";
67+
}
68+
6169
string get_writable_config_path(const string& filename)
6270
{
6371
/* Only stuff in the user_config_dir is supposed to be writable,

libswirl/stdclass.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ void set_user_config_dir(const string& dir);
171171
void set_user_data_dir(const string& dir);
172172
void add_system_config_dir(const string& dir);
173173
void add_system_data_dir(const string& dir);
174+
void clear_dirs();
174175

175176
//subpath format: /data/fsca-table.bit
176177
string get_writable_config_path(const string& filename);

reicast/cmake/config.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ if(${HOST_OS} EQUAL ${OS_LINUX})
259259
# option SUPPORT_X11
260260
# option FEAT_HAS_NIXPROF
261261
# option EMSCripten
262-
add_definitions(-DUSES_HOMEDIR)
263262
endif()
264263

265264
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")

reicast/linux/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ LDFLAGS := -g -Wl,-Map,$(notdir $@).map,--gc-sections -Wl,-O3 -Wl,--sort-common
2727
INCS :=
2828
LIBS := -lm -lpthread -lutil #defaults
2929

30-
CFLAGS := -g -O3 -D RELEASE -c -D USES_HOMEDIR -fopenmp # defaults
30+
CFLAGS := -g -O3 -D RELEASE -c -fopenmp # defaults
3131
CFLAGS += -frename-registers -fno-strict-aliasing
3232
CFLAGS += -ffast-math -ftree-vectorize
3333

0 commit comments

Comments
 (0)