4 #include "muimiamipanel_intern.h"
5 #include "muimiamipanel_iffprefs.h"
6 #include "muimiamipanel_misc.h"
9 saveIFFPrefs(UBYTE
*file
,struct MPS_Prefs
*prefs
, struct MiamiPanelBase_intern
*MiamiPanelBaseIntern
)
11 register struct IFFHandle
*iffh
;
12 register ULONG res
= FALSE
;
14 if (iffh
= AllocIFF())
16 if (iffh
->iff_Stream
= Open(file
,MODE_NEWFILE
))
20 if (!OpenIFF(iffh
,IFFF_WRITE
))
22 struct PrefHeader prhd
;
23 register struct ifnode
*ifnode
;
25 if (PushChunk(iffh
,ID_PREF
,ID_FORM
,IFFSIZE_UNKNOWN
)) goto fail
;
26 if (PushChunk(iffh
,ID_PREF
,ID_PRHD
,sizeof(struct PrefHeader
))) goto fail
;
28 prhd
.ph_Version
= MPV_Prefs_Version
;
32 if (WriteChunkBytes(iffh
,&prhd
,sizeof(struct PrefHeader
))!=sizeof(struct PrefHeader
))
35 if (PopChunk(iffh
)) goto fail
;
37 if (PushChunk(iffh
,ID_PREF
,ID_Prefs
,SIZE_Prefs
)) goto fail
;
38 if (WriteChunkBytes(iffh
,prefs
,SIZE_Prefs
)!=SIZE_Prefs
) goto fail
;
39 if (PopChunk(iffh
)) goto fail
;
41 for (ifnode
= (struct ifnode
*)prefs
->iflist
.mlh_Head
; ifnode
->link
.mln_Succ
; ifnode
= (struct ifnode
*)ifnode
->link
.mln_Succ
)
43 if (PushChunk(iffh
,ID_PREF
,ID_IFNode
,SIZE_IFNode
)) goto fail
;
44 if (WriteChunkBytes(iffh
,&ifnode
->name
,SIZE_IFNode
)!=SIZE_IFNode
) goto fail
;
45 if (PopChunk(iffh
)) goto fail
;
53 Close(iffh
->iff_Stream
);
59 if (!res
) DeleteFile(file
);
64 /**************************************************************************/
67 loadIFFPrefs(ULONG where
,struct MPS_Prefs
*prefs
, struct MiamiPanelBase_intern
*MiamiPanelBaseIntern
)
69 register struct IFFHandle
*iffh
;
70 register ULONG res
= FALSE
;
72 NEWLIST(&prefs
->iflist
);
74 if (iffh
= AllocIFF())
78 if (where
& MPV_LoadPrefs_Env
)
80 file
= Open(DEF_ENVFILE
,MODE_OLDFILE
);
81 if (!file
&& (where
& MPV_LoadPrefs_FallBack
))
82 file
= Open(DEF_ENVARCFILE
,MODE_OLDFILE
);
84 else file
= Open(DEF_ENVARCFILE
,MODE_OLDFILE
);
88 iffh
->iff_Stream
= file
;
92 if (!OpenIFF(iffh
,IFFF_READ
))
94 struct PrefHeader prhd
;
95 register struct ContextNode
*cn
;
97 if (StopChunk(iffh
,ID_PREF
,ID_PRHD
)) goto fail
;
98 if (StopChunk(iffh
,ID_PREF
,ID_Prefs
)) goto fail
;
99 if (StopChunk(iffh
,ID_PREF
,ID_IFNode
)) goto fail
;
101 if (ParseIFF(iffh
,IFFPARSE_SCAN
)) goto fail
;
103 if (!(cn
= CurrentChunk(iffh
))) goto fail
;
105 if ((cn
->cn_Type
!=ID_PREF
) || (cn
->cn_ID
!=ID_PRHD
) ||
106 (cn
->cn_Size
!=sizeof(struct PrefHeader
))) goto fail
;
108 if (ReadChunkBytes(iffh
,&prhd
,cn
->cn_Size
)!=cn
->cn_Size
) goto fail
;
110 if (prhd
.ph_Version
>MPV_Prefs_Version
) goto fail
;
114 register ULONG error
;
116 error
= ParseIFF(iffh
,IFFPARSE_SCAN
);
117 if (error
==IFFERR_EOF
) break;
118 else if (error
) goto fail
;
120 if (!(cn
= CurrentChunk(iffh
))) goto fail
;
122 if (cn
->cn_Type
!=ID_PREF
) continue;
124 if ((cn
->cn_ID
==ID_Prefs
) && (cn
->cn_Size
==SIZE_Prefs
))
126 if (ReadChunkBytes(iffh
,prefs
,cn
->cn_Size
)!=cn
->cn_Size
)
130 if ((cn
->cn_ID
==ID_IFNode
) && (cn
->cn_Size
==SIZE_IFNode
))
132 struct ifnode ifnode
;
134 if (ReadChunkBytes(iffh
,&ifnode
.name
,cn
->cn_Size
)!=cn
->cn_Size
)
137 createIFNode(prefs
, ifnode
.name
, ifnode
.scale
, MiamiPanelBaseIntern
);
143 fail
: CloseIFF(iffh
);
152 //if (!res) freeIFList(prefs);
157 /**************************************************************************/