revert between 56095 -> 55830 in arch
[AROS.git] / workbench / network / stacks / AROSTCP / MUI.MiamiPanel / muimiamipanel_iffprefs.c
blob12b76310044e78ddc97d0ef3f9d8921fc54ca5c7
2 #include <proto/dos.h>
4 #include "muimiamipanel_intern.h"
5 #include "muimiamipanel_iffprefs.h"
6 #include "muimiamipanel_misc.h"
8 ULONG
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))
18 InitIFFasDOS(iffh);
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;
29 prhd.ph_Type = 0;
30 prhd.ph_Flags = 0;
32 if (WriteChunkBytes(iffh,&prhd,sizeof(struct PrefHeader))!=sizeof(struct PrefHeader))
33 goto fail;
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;
48 res = TRUE;
50 fail: CloseIFF(iffh);
53 Close(iffh->iff_Stream);
56 FreeIFF(iffh);
59 if (!res) DeleteFile(file);
61 return res;
64 /**************************************************************************/
66 ULONG
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())
76 register BPTR file;
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);
86 if (file)
88 iffh->iff_Stream = file;
90 InitIFFasDOS(iffh);
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;
112 for (;;)
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)
127 goto fail;
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)
135 goto fail;
137 createIFNode(prefs, ifnode.name, ifnode.scale, MiamiPanelBaseIntern);
141 res = TRUE;
143 fail: CloseIFF(iffh);
146 Close(file);
149 FreeIFF(iffh);
152 //if (!res) freeIFList(prefs);
154 return res;
157 /**************************************************************************/