Added Amiga ToolTypes parser.

Initially this allows setting the location of the Users directory, and the current user's name.
This commit is contained in:
Chris Young 2015-11-22 00:06:10 +00:00
parent 5e24a802b0
commit f7ebec7142
5 changed files with 82 additions and 4 deletions

View File

@ -117,6 +117,17 @@ FORCE = Force new instance of NetSurf to open (has some limitations, use for de
NSOPTS = Catches everything else and passes it to the NetSurf core command line parser NSOPTS = Catches everything else and passes it to the NetSurf core command line parser
@endnode @endnode
@node tooltypes "ToolTypes"
Supported tooltypes are:
@{b}USERSDIR@{ub}
Location of the Users directory. This should contain the "Users" part of the path, NetSurf will append the username. Defaults to PROGDIR:Users.
The user directories contain user-specific preferences and cache data. Always locate them on fast, non-volatile, writeable media.
@{b}USER@{ub}
Current user. Defaults to the value of the USER env-var, or Default.
@endnode
@node options "Options file" @node options "Options file"
The options file is stored in @{"Users/Default/Choices" link Users/Default/Choices/Main} by default. Most of the settings can be changed from within NetSurf by selecting Edit preferences from the Settings menu. The options file is stored in @{"Users/Default/Choices" link Users/Default/Choices/Main} by default. Most of the settings can be changed from within NetSurf by selecting Edit preferences from the Settings menu.

View File

@ -31,6 +31,7 @@
#include <proto/dos.h> #include <proto/dos.h>
#include <proto/exec.h> #include <proto/exec.h>
#include <proto/graphics.h> #include <proto/graphics.h>
#include <proto/icon.h>
#include <proto/intuition.h> #include <proto/intuition.h>
#include <proto/keymap.h> #include <proto/keymap.h>
#include <proto/locale.h> #include <proto/locale.h>
@ -188,7 +189,9 @@ static struct Hook newprefs_hook;
static STRPTR temp_homepage_url = NULL; static STRPTR temp_homepage_url = NULL;
static bool cli_force = false; static bool cli_force = false;
static char *current_user; #define USERS_DIR "PROGDIR:Users"
static char *users_dir = NULL;
static char *current_user = NULL;
static char *current_user_dir; static char *current_user_dir;
static char *current_user_faviconcache; static char *current_user_faviconcache;
@ -855,6 +858,42 @@ static void ami_gui_commandline(int *argc, char **argv)
} }
} }
static void ami_gui_read_tooltypes(struct WBArg *wbarg)
{
struct DiskObject *dobj;
STRPTR *toolarray;
char *s;
if((*wbarg->wa_Name) && (dobj = GetDiskObject(wbarg->wa_Name))) {
toolarray = (STRPTR *)dobj->do_ToolTypes;
if((s = (char *)FindToolType(toolarray,"USERSDIR"))) users_dir = ASPrintf("%s", s);
if((s = (char *)FindToolType(toolarray,"USER"))) current_user = ASPrintf("%s", s);
FreeDiskObject(dobj);
}
}
static void ami_gui_read_all_tooltypes(int argc, char **argv)
{
struct WBStartup *WBenchMsg;
struct WBArg *wbarg;
char i;
LONG olddir = -1;
if(argc == 0) { /* Started from WB */
WBenchMsg = (struct WBStartup *)argv;
for(i = 0, wbarg = WBenchMsg->sm_ArgList; i < WBenchMsg->sm_NumArgs; i++,wbarg++) {
olddir =-1;
if((wbarg->wa_Lock) && (*wbarg->wa_Name))
olddir = SetCurrentDir(wbarg->wa_Lock);
ami_gui_read_tooltypes(wbarg);
if(olddir !=-1) SetCurrentDir(olddir);
}
}
}
static void gui_init2(int argc, char** argv) static void gui_init2(int argc, char** argv)
{ {
@ -965,6 +1004,7 @@ static void gui_init2(int argc, char** argv)
temp_homepage_url = NULL; temp_homepage_url = NULL;
} }
} }
/* this should be where we read tooltypes, but it's too late for that now */
} }
} }
@ -5427,10 +5467,36 @@ int main(int argc, char** argv)
return RETURN_FAIL; return RETURN_FAIL;
} }
ami_gui_read_all_tooltypes(argc, argv);
if(current_user == NULL) {
user = GetVar("user", temp, 1024, GVF_GLOBAL_ONLY); user = GetVar("user", temp, 1024, GVF_GLOBAL_ONLY);
current_user = ASPrintf("%s", (user == -1) ? "Default" : temp); current_user = ASPrintf("%s", (user == -1) ? "Default" : temp);
}
LOG("User: %s", current_user); LOG("User: %s", current_user);
current_user_dir = ASPrintf("PROGDIR:Users/%s", current_user);
if(users_dir == NULL) {
users_dir = ASPrintf("%s", USERS_DIR);
if(users_dir == NULL) {
ami_misc_fatal_error("Failed to allocate memory");
return RETURN_FAIL;
}
}
int len = strlen(current_user);
len += strlen(users_dir);
len += 2; /* for poss path sep and NULL term */
current_user_dir = AllocVecTags(len, NULL);
if(current_user_dir == NULL) {
ami_misc_fatal_error("Failed to allocate memory");
return RETURN_FAIL;
}
strlcpy(current_user_dir, users_dir, len);
AddPart(current_user_dir, current_user, len);
FreeVec(users_dir);
LOG("User dir: %s", current_user_dir);
if((lock = CreateDirTree(current_user_dir))) if((lock = CreateDirTree(current_user_dir)))
UnLock(lock); UnLock(lock);

View File

@ -144,6 +144,7 @@
#define FOpen(A,B,C) Open(A,B) #define FOpen(A,B,C) Open(A,B)
#define FClose(A) Close(A) #define FClose(A) Close(A)
#define CreateDirTree(D) CreateDir(D) /*\todo This isn't quite right */ #define CreateDirTree(D) CreateDir(D) /*\todo This isn't quite right */
#define SetCurrentDir(L) CurrentDir(L)
#define DevNameFromLock(A,B,C,D) NameFromLock(A,B,C) #define DevNameFromLock(A,B,C,D) NameFromLock(A,B,C)
/* Exec */ /* Exec */