fix function to take the hook param
[AROS.git] / workbench / libs / datatypes / savedtobjecta.c
blobf9e4b7e5d71be25e0bd1436f95d9d38e533a504d
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <string.h>
8 #include <proto/utility.h>
9 #include <proto/icon.h>
10 #include <proto/dos.h>
11 #include <proto/datatypes.h>
12 #include <exec/memory.h>
13 #include <datatypes/datatypesclass.h>
14 #include <workbench/icon.h>
15 #include <workbench/workbench.h>
16 #include <utility/tagitem.h>
17 #include "datatypes_intern.h"
19 STRPTR CreateIconName(STRPTR name, struct Library *DataTypesBase);
21 /*****************************************************************************
23 NAME */
25 AROS_LH7(ULONG, SaveDTObjectA,
27 /* SYNOPSIS */
28 AROS_LHA(Object *, o , A0),
29 AROS_LHA(struct Window *, win , A1),
30 AROS_LHA(struct Requester *, req , A2),
31 AROS_LHA(STRPTR , file , A3),
32 AROS_LHA(ULONG , mode , D0),
33 AROS_LHA(BOOL , saveicon, D1),
34 AROS_LHA(struct TagItem *, attrs , A4),
36 /* LOCATION */
37 struct Library *, DataTypesBase, 49, DataTypes)
39 /* FUNCTION
41 Save the contents of an object to a file using DTM_WRITE.
43 INPUTS
45 o -- data type object to write to a file
46 win -- window the object is attached to
47 req -- requester the object is attached to
48 file -- name of the file to save the object to
49 mode -- save mode (RAW, IFF etc.), one of the DTWM_ identifiers
50 saveicon -- should an icon be saved together with the file
51 attrs -- additional attributes (these are subclass specific)
53 RESULT
55 The return value of DTM_WRITE.
57 NOTES
59 If DTM_WRITE returns 0, the file will be deleted.
61 EXAMPLE
63 BUGS
65 SEE ALSO
67 INTERNALS
69 *****************************************************************************/
71 AROS_LIBFUNC_INIT
73 ULONG err;
74 struct dtWrite write;
75 struct DataType *dt;
76 ULONG rc = 0;
77 struct Library *IconBase = OpenLibrary("icon.library", 39L);
78 struct TagItem tags[2] =
80 { DTA_DataType, (STACKIPTR)&dt },
81 { TAG_DONE , (STACKIPTR)NULL }
84 if(o == NULL || file == NULL)
86 SetIoErr(ERROR_REQUIRED_ARG_MISSING);
87 rc = 0;
88 goto cleanup;
91 write.MethodID = DTM_WRITE;
92 write.dtw_GInfo = NULL;
93 write.dtw_Mode = mode;
94 write.dtw_AttrList = attrs;
96 if(GetDTAttrsA(o, (struct TagItem *)&tags) == 0)
98 SetIoErr(ERROR_OBJECT_WRONG_TYPE);
99 rc = 0;
100 goto cleanup;
103 write.dtw_FileHandle = Open(file, MODE_NEWFILE);
104 if (write.dtw_FileHandle == BNULL)
106 rc = 0;
107 goto cleanup;
110 rc = DoDTMethodA(o, win, req, (Msg)&write);
112 /* Save possible error */
113 err = IoErr();
115 if (Close(write.dtw_FileHandle) == DOSFALSE)
117 if(rc != 0) SetIoErr(err);
118 else DeleteFile(file);
120 rc = 0;
121 goto cleanup;
124 /* If the DTM_WRITE didn't succeed, we delete the file */
125 if(rc == 0)
127 DeleteFile(file);
128 rc = 0;
129 goto cleanup;
132 if (saveicon && IconBase != NULL)
134 struct DiskObject *icon = GetDiskObjectNew(file);
136 if(icon != NULL)
138 PutDiskObject(file, icon);
139 FreeDiskObject(icon);
143 cleanup:
144 if (IconBase != NULL) CloseLibrary(IconBase);
146 return rc;
148 AROS_LIBFUNC_EXIT
149 } /* SaveDTObjectA() */