3 #include <aros/debug.h>
5 #include <proto/exec.h>
7 #include <proto/icon.h>
8 #include <workbench/icon.h>
12 static const char version
[] __attribute__((used
)) = "\0$VER: IconInject 0.1 (06.03.09) © The AROS Dev Team" ;
15 const UBYTE iitemplate
[] =
29 int main(int argc
, char **argv
)
31 struct RDArgs
*iireadargs
;
32 struct ArgList
*IIArgList
= &arglist
;
34 char *IISourceIcon
= NULL
;
35 char *IITargetIcon
= NULL
;
37 iireadargs
= ReadArgs(iitemplate
, (IPTR
*)IIArgList
, NULL
);
40 if ((IIArgList
->sourceIcon
) && (IIArgList
->targetIcon
))
42 D(bug("[IconInject] Source @ %p, Dest @ %p\n", IIArgList
->sourceIcon
, IIArgList
->targetIcon
));
43 D(bug("[IconInject] '%s' -> '%s'\n", IIArgList
->sourceIcon
, IIArgList
->targetIcon
));
44 if ((strlen(IIArgList
->sourceIcon
) > 5) && (strncmp(IIArgList
->sourceIcon
+ strlen(IIArgList
->sourceIcon
) - 5, ".info",5)))
46 if ((IISourceIcon
= AllocVec(strlen(IIArgList
->sourceIcon
) - 4, MEMF_CLEAR
)) != NULL
)
47 CopyMem(IIArgList
->sourceIcon
, IISourceIcon
, strlen(IIArgList
->sourceIcon
) - 5);
51 /* "TODO: Check if the name is a device and append disk.." */
52 if ((IISourceIcon
= AllocVec(strlen(IIArgList
->sourceIcon
) + 1, MEMF_CLEAR
)) != NULL
)
53 CopyMem(IIArgList
->sourceIcon
, IISourceIcon
, strlen(IIArgList
->sourceIcon
) - 5);
56 if ((strlen(IIArgList
->targetIcon
) > 5) && (strncmp(IIArgList
->targetIcon
+ strlen(IIArgList
->targetIcon
) - 5, ".info",5)))
58 if ((IITargetIcon
= AllocVec(strlen(IIArgList
->targetIcon
) - 4, MEMF_CLEAR
)) != NULL
)
59 CopyMem(IIArgList
->targetIcon
, IITargetIcon
, strlen(IIArgList
->targetIcon
) - 5);
63 /* "TODO: Check if the name is a device and append disk.." */
64 if ((IITargetIcon
= AllocVec(strlen(IIArgList
->targetIcon
) + 1, MEMF_CLEAR
)) != NULL
)
65 CopyMem(IIArgList
->targetIcon
, IITargetIcon
, strlen(IIArgList
->targetIcon
) - 5);
68 if (IISourceIcon
&& IITargetIcon
)
70 struct DiskObject
*sourceIconDOB
= NULL
;
71 struct DiskObject
*targetIconDOB
= NULL
;
72 IPTR tmpGadRender
= 0;
73 IPTR tmpSelRender
= 0;
75 D(bug("[IconInject] '%s' -> '%s'\n", IISourceIcon
, IITargetIcon
));
77 sourceIconDOB
= GetIconTags
80 ICONGETA_FailIfUnavailable
, FALSE
,
84 targetIconDOB
= GetIconTags
87 ICONGETA_FailIfUnavailable
, FALSE
,
91 if (sourceIconDOB
&& targetIconDOB
)
93 if (IIArgList
->replaceimages
)
95 if (IIArgList
->verbose
)
96 printf("Replacing ICON IMAGERY in %s.info from %s.info\n", IITargetIcon
, IISourceIcon
);
98 tmpGadRender
= (IPTR
)targetIconDOB
->do_Gadget
.GadgetRender
;
99 tmpSelRender
= (IPTR
)targetIconDOB
->do_Gadget
.SelectRender
;
101 targetIconDOB
->do_Gadget
.GadgetRender
= sourceIconDOB
->do_Gadget
.GadgetRender
;
102 targetIconDOB
->do_Gadget
.SelectRender
= sourceIconDOB
->do_Gadget
.SelectRender
;
105 // Update the icon ..
106 PutIconTagList(IITargetIcon
, targetIconDOB
, NULL
);
108 if (IIArgList
->replaceimages
)
110 targetIconDOB
->do_Gadget
.GadgetRender
= (APTR
)tmpGadRender
;
111 targetIconDOB
->do_Gadget
.SelectRender
= (APTR
)tmpSelRender
;
115 // Couldnt obtain one of the Icons ..
120 //Failed to allocate Icon name buffer(s) ..
125 //Missing arguments.. display a gui?
126 printf("no args ..\n");
129 if (IISourceIcon
) FreeVec(IISourceIcon
);
130 if (IITargetIcon
) FreeVec(IITargetIcon
);