X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;ds=inline;f=libchimara%2Ffileref.c;h=d20e1f24da228aea4af649af28fe8c5b1c15e4e2;hb=2c42a309e26f313d2cddc2910019e96305ab1e57;hp=2b5cf53efd65d9f8c04bc32732699e16c6db33a4;hpb=0b85f1dd5993e2ed111ec2ba13bbbb4ebda06ada;p=rodin%2Fchimara.git
diff --git a/libchimara/fileref.c b/libchimara/fileref.c
index 2b5cf53..d20e1f2 100644
--- a/libchimara/fileref.c
+++ b/libchimara/fileref.c
@@ -57,7 +57,7 @@ glk_fileref_get_rock(frefid_t fref)
}
/* Internal function: create a fileref using the given parameters. */
-static frefid_t
+frefid_t
fileref_new(gchar *filename, glui32 rock, glui32 usage, glui32 orig_filemode)
{
g_return_val_if_fail(filename != NULL, NULL);
@@ -137,30 +137,31 @@ glk_fileref_create_temp(glui32 usage, glui32 rock)
* Chimara
*
* Chimara uses a GtkFileChooserDialog.
+ * linkend="gtk-GtkFileChooserDialog">GtkFileChooserDialog. The default
+ * starting location for the dialog may be set with glkunix_set_base_file().
*
*
* @fmode must be one of these values:
*
*
- * #filemode_Read
+ * %filemode_Read
* The file must already exist; and the player will be asked
* to select from existing files which match the usage.
*
*
- * #filemode_Write
+ * %filemode_Write
* The file should not exist; if the player selects an
* existing file, he will be warned that it will be replaced.
*
*
*
- * #filemode_ReadWrite
+ * %filemode_ReadWrite
* The file may or may not exist; if it already exists, the
* player will be warned that it will be modified.
*
*
- * #filemode_WriteAppend
- * Same behavior as #filemode_ReadWrite.
+ * %filemode_WriteAppend
+ * Same behavior as %filemode_ReadWrite.
*
*
*
@@ -224,6 +225,9 @@ glk_fileref_create_by_prompt(glui32 usage, glui32 fmode, glui32 rock)
return NULL;
}
+ if(glk_data->current_dir)
+ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), glk_data->current_dir);
+
if(gtk_dialog_run( GTK_DIALOG(chooser) ) != GTK_RESPONSE_ACCEPT)
{
gtk_widget_destroy(chooser);
@@ -254,7 +258,8 @@ glk_fileref_create_by_prompt(glui32 usage, glui32 fmode, glui32 rock)
*
* Chimara
*
- * In Chimara, the file is created in the current working directory.
+ * In Chimara, the file is created in the directory last set by
+ * glkunix_set_base_file(), and otherwise in the current working directory.
*
*
* Since filenames are highly platform-specific, you should use
@@ -284,6 +289,14 @@ glk_fileref_create_by_name(glui32 usage, char *name, glui32 rock)
{
g_return_val_if_fail(name != NULL && strlen(name) > 0, NULL);
+ /* Do any string-munging here to remove illegal Latin-1 characters from
+ filename. On ext3, the only illegal characters are '/' and '\0'. */
+
+ char *ptr = name;
+ while(*ptr++)
+ if(*ptr == '/')
+ *ptr = '_';
+
/* Find out what encoding filenames are in */
const gchar **charsets; /* Do not free */
g_get_filename_charsets(&charsets);
@@ -297,14 +310,16 @@ glk_fileref_create_by_name(glui32 usage, char *name, glui32 rock)
WARNING_S("Error during latin1->filename conversion", error->message);
return NULL;
}
-
- /* Do any string-munging here to remove illegal characters from filename.
- On ext3, the only illegal characters are '/' and '\0'. TODO: Should this
- function be allowed to reference files in other directories, or should we
- disallow '/'? */
-
- frefid_t f = fileref_new(osname, rock, usage, filemode_ReadWrite);
+
+ gchar *path;
+ if(glk_data->current_dir)
+ path = g_build_filename(glk_data->current_dir, osname, NULL);
+ else
+ path = g_strdup(osname);
g_free(osname);
+
+ frefid_t f = fileref_new(path, rock, usage, filemode_ReadWrite);
+ g_free(path);
return f;
}
@@ -318,7 +333,7 @@ glk_fileref_create_by_name(glui32 usage, char *name, glui32 rock)
* original fileref is not modified.)
*
* The use of this function can be tricky. If you change the type of the fileref
- * (#fileusage_Data, #fileusage_SavedGame, etc), the new reference may or may
+ * (%fileusage_Data, %fileusage_SavedGame, etc), the new reference may or may
* not point to the same actual disk file.
*
*
@@ -330,8 +345,8 @@ glk_fileref_create_by_name(glui32 usage, char *name, glui32 rock)
* unpredictable. It is safest to change the type of a fileref only if it refers
* to a nonexistent file.
*
- * If you change the mode of a fileref (#fileusage_TextMode,
- * #fileusage_BinaryMode), but leave the rest of the type unchanged, the new
+ * If you change the mode of a fileref (%fileusage_TextMode,
+ * %fileusage_BinaryMode), but leave the rest of the type unchanged, the new
* fileref will definitely point to the same disk file as the old one.
*
* Obviously, if you write to a file in text mode and then read from it in