2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
9 /*********************************************************************************************/
11 #include <aros/macros.h>
14 #include <aros/debug.h>
16 #include <proto/exec.h>
17 #include <proto/dos.h>
18 #include <proto/iffparse.h>
20 #include <prefs/prefhdr.h>
21 #include <devices/inputevent.h>
30 /*********************************************************************************************/
32 #define PREFS_PATH_ENVARC "ENVARC:SYS/icontrol.prefs"
33 #define PREFS_PATH_ENV "ENV:SYS/icontrol.prefs"
35 /*********************************************************************************************/
44 /*********************************************************************************************/
46 struct IControlPrefs icontrolprefs
;
48 /*********************************************************************************************/
50 static BOOL
Prefs_Load(STRPTR from
)
54 BPTR fh
= Open(from
, MODE_OLDFILE
);
57 retval
= Prefs_ImportFH(fh
);
64 /*********************************************************************************************/
66 BOOL
Prefs_ImportFH(BPTR fh
)
68 struct IControlPrefs loadprefs
;
69 struct IFFHandle
*iff
;
72 if ((iff
= AllocIFF()))
74 iff
->iff_Stream
= (IPTR
)fh
;
78 if (!OpenIFF(iff
, IFFF_READ
))
80 D(bug("LoadPrefs: OpenIFF okay.\n"));
82 if (!StopChunk(iff
, ID_PREF
, ID_ICTL
))
84 D(bug("LoadPrefs: StopChunk okay.\n"));
86 if (!ParseIFF(iff
, IFFPARSE_SCAN
))
88 struct ContextNode
*cn
;
90 D(bug("LoadPrefs: ParseIFF okay.\n"));
92 cn
= CurrentChunk(iff
);
94 if (cn
->cn_Size
== sizeof(struct IControlPrefs
))
96 D(bug("LoadPrefs: ID_ICTL chunk size okay.\n"));
98 if (ReadChunkBytes(iff
, &loadprefs
, sizeof(struct IControlPrefs
)) == sizeof(struct IControlPrefs
))
100 D(bug("LoadPrefs: Reading chunk successful.\n"));
102 CopyMem(loadprefs
.ic_Reserved
, icontrolprefs
.ic_Reserved
, sizeof(icontrolprefs
.ic_Reserved
));
104 icontrolprefs
.ic_TimeOut
= AROS_BE2WORD(loadprefs
.ic_TimeOut
);
105 icontrolprefs
.ic_MetaDrag
= AROS_BE2WORD(loadprefs
.ic_MetaDrag
);
106 icontrolprefs
.ic_Flags
= AROS_BE2LONG(loadprefs
.ic_Flags
);
107 icontrolprefs
.ic_WBtoFront
= loadprefs
.ic_WBtoFront
;
108 icontrolprefs
.ic_FrontToBack
= loadprefs
.ic_FrontToBack
;
109 icontrolprefs
.ic_ReqTrue
= loadprefs
.ic_ReqTrue
;
110 icontrolprefs
.ic_ReqFalse
= loadprefs
.ic_ReqFalse
;
111 icontrolprefs
.ic_Reserved2
= AROS_BE2WORD(loadprefs
.ic_Reserved2
);
112 icontrolprefs
.ic_VDragModes
[0] = AROS_BE2WORD(loadprefs
.ic_VDragModes
[0]);
113 icontrolprefs
.ic_VDragModes
[1] = AROS_BE2WORD(loadprefs
.ic_VDragModes
[1]);
115 D(bug("LoadPrefs: Everything okay :-)\n"));
120 } /* if (!ParseIFF(iff, IFFPARSE_SCAN)) */
121 } /* if (!StopChunk(iff, ID_PREF, ID_ICTL)) */
123 } /* if (!OpenIFF(iff, IFFF_READ)) */
125 } /* if ((iff = AllocIFF())) */
129 /*********************************************************************************************/
131 BOOL
Prefs_ExportFH(BPTR fh
)
133 struct IControlPrefs saveprefs
;
134 struct IFFHandle
*iff
;
137 BOOL delete_if_error
= FALSE
;
140 CopyMem(icontrolprefs
.ic_Reserved
, saveprefs
.ic_Reserved
, sizeof(icontrolprefs
.ic_Reserved
));
142 saveprefs
.ic_TimeOut
= AROS_WORD2BE(icontrolprefs
.ic_TimeOut
);
143 saveprefs
.ic_MetaDrag
= AROS_WORD2BE(icontrolprefs
.ic_MetaDrag
);
144 saveprefs
.ic_Flags
= AROS_LONG2BE(icontrolprefs
.ic_Flags
);
145 saveprefs
.ic_WBtoFront
= icontrolprefs
.ic_WBtoFront
;
146 saveprefs
.ic_FrontToBack
= icontrolprefs
.ic_FrontToBack
;
147 saveprefs
.ic_ReqTrue
= icontrolprefs
.ic_ReqTrue
;
148 saveprefs
.ic_ReqFalse
= icontrolprefs
.ic_ReqFalse
;
149 saveprefs
.ic_Reserved2
= AROS_WORD2BE(icontrolprefs
.ic_Reserved2
);
150 saveprefs
.ic_VDragModes
[0] = AROS_WORD2BE(icontrolprefs
.ic_VDragModes
[0]);
151 saveprefs
.ic_VDragModes
[1] = AROS_WORD2BE(icontrolprefs
.ic_VDragModes
[1]);
153 D(bug("SavePrefsFH: fh: %lx\n", fh
));
155 if ((iff
= AllocIFF()))
157 iff
->iff_Stream
= (IPTR
) fh
;
158 D(bug("SavePrefsFH: stream opened.\n"));
161 delete_if_error
= TRUE
;
166 if (!OpenIFF(iff
, IFFF_WRITE
))
168 D(bug("SavePrefsFH: OpenIFF okay.\n"));
170 if (!PushChunk(iff
, ID_PREF
, ID_FORM
, IFFSIZE_UNKNOWN
))
172 D(bug("SavePrefsFH: PushChunk(FORM) okay.\n"));
174 if (!PushChunk(iff
, ID_PREF
, ID_PRHD
, sizeof(struct FilePrefHeader
)))
176 struct FilePrefHeader head
;
178 D(bug("SavePrefsFH: PushChunk(PRHD) okay.\n"));
180 head
.ph_Version
= PHV_CURRENT
;
185 head
.ph_Flags
[3] = 0;
187 if (WriteChunkBytes(iff
, &head
, sizeof(head
)) == sizeof(head
))
189 D(bug("SavePrefsFH: WriteChunkBytes(PRHD) okay.\n"));
193 if (!PushChunk(iff
, ID_PREF
, ID_ICTL
, sizeof(struct IControlPrefs
)))
195 D(bug("SavePrefsFH: PushChunk(LCLE) okay.\n"));
197 if (WriteChunkBytes(iff
, &saveprefs
, sizeof(saveprefs
)) == sizeof(saveprefs
))
199 D(bug("SavePrefsFH: WriteChunkBytes(ICTL) okay.\n"));
200 D(bug("SavePrefsFH: Everything okay :-)\n"));
205 } /* if (!PushChunk(iff, ID_PREF, ID_ICTL, sizeof(struct IControlPrefs))) */
206 } /* if (WriteChunkBytes(iff, &head, sizeof(head)) == sizeof(head)) */
211 } /* if (!PushChunk(iff, ID_PREF, ID_PRHD, sizeof(struct PrefHeader))) */
213 } /* if (!PushChunk(iff, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN)) */
215 } /* if (!OpenIFF(iff, IFFFWRITE)) */
218 } /* if ((iff = AllocIFF())) */
221 if (!retval
&& delete_if_error
)
223 DeleteFile(filename
);
230 /*********************************************************************************************/
232 BOOL
Prefs_HandleArgs(STRPTR from
, BOOL use
, BOOL save
)
238 if (!Prefs_Load(from
))
240 ShowMessage("Can't read from input file");
246 if (!Prefs_Load(PREFS_PATH_ENV
))
248 if (!Prefs_Load(PREFS_PATH_ENVARC
))
252 "Can't read from file " PREFS_PATH_ENVARC
253 ".\nUsing default values."
262 fh
= Open(PREFS_PATH_ENV
, MODE_NEWFILE
);
270 ShowMessage("Cant' open " PREFS_PATH_ENV
" for writing.");
275 fh
= Open(PREFS_PATH_ENVARC
, MODE_NEWFILE
);
283 ShowMessage("Cant' open " PREFS_PATH_ENVARC
" for writing.");
289 /*********************************************************************************************/
291 BOOL
Prefs_Default(VOID
)
293 icontrolprefs
.ic_Reserved
[0] = 0;
294 icontrolprefs
.ic_Reserved
[1] = 0;
295 icontrolprefs
.ic_Reserved
[2] = 0;
296 icontrolprefs
.ic_Reserved
[3] = 0;
297 icontrolprefs
.ic_TimeOut
= 50;
298 icontrolprefs
.ic_MetaDrag
= IEQUALIFIER_LCOMMAND
;
299 icontrolprefs
.ic_Flags
= ICF_3DMENUS
|
305 /* FIXME: check whether ICF_DEFPUBSCREEN is set as default */
306 icontrolprefs
.ic_WBtoFront
= 'N';
307 icontrolprefs
.ic_FrontToBack
= 'M';
308 icontrolprefs
.ic_ReqTrue
= 'V';
309 icontrolprefs
.ic_ReqFalse
= 'B';
310 icontrolprefs
.ic_VDragModes
[0] = 0;
311 icontrolprefs
.ic_VDragModes
[1] = 0;