Icon.library ?
Icon.library ?
I would like to program 2 Cli commands to be used in scripts
a) one giving the type of an icon (tool, project ..)
b) one permitting to change the type of an icon to an other one you specify in the command line
I guess it's ion.library that i should use, but the autodoc is not that easy to grasp.
I would be bery gratefull for some help: what functions should i use ?
a) one giving the type of an icon (tool, project ..)
b) one permitting to change the type of an icon to an other one you specify in the command line
I guess it's ion.library that i should use, but the autodoc is not that easy to grasp.
I would be bery gratefull for some help: what functions should i use ?
Re: Icon.library ?
Basically it is something like this to change the icon type of "disk.info" from whatever to a tool icon:JosDuchIt wrote:I would like to program 2 Cli commands to be used in scripts
a) one giving the type of an icon (tool, project ..)
b) one permitting to change the type of an icon to an other one you specify in the command line
I guess it's ion.library that i should use, but the autodoc is not that easy to grasp.
I would be bery gratefull for some help: what functions should i use ?
Code: Select all
icon = GetDiskObject("disk");
icon->do_Type = WBTOOL;
PutDiskObject("disk", icon);
FreeDiskObject(icon);

If you need to do more complex operations on the icon then perhaps GetIconTags() and PutIconTags() are more suitable functions.
- thomasrapp
- Posts: 318
- Joined: Sun Jun 19, 2011 12:22 am
Re: Icon.library ?
Turning a disk.info into a tool will hide the partition...
Re: Icon.library ?
Thanks, also for the warning.
as i had to hunt for the other do_type values
as i had to hunt for the other do_type values
WBDISK The root of a disk
WBDRAWER A directory on the disk
WBTOOL An executable program
WBPROJECT A data file
WBGARBAGE The Trashcan directory
WBKICK A Kickstart disk
WBAPPICON Any object not directly associated
with a filing system object, such as
a print spooler (new in Release 2).
Table 14-2: Workbench Object Types
- thomasrapp
- Posts: 318
- Joined: Sun Jun 19, 2011 12:22 am
Re: Icon.library ?
Here is a "MakeTrash" command I wrote some time ago:
Code: Select all
#include <proto/dos.h>
#include <proto/icon.h>
int main (void)
{
struct RDArgs *rdargs;
struct {
char *path;
} args = {0};
int rc = RETURN_FAIL;
BPTR lock;
struct DiskObject *dob;
rdargs = ReadArgs ("PATH/A",(LONG *)&args,NULL);
if (!rdargs)
{
PrintFault (IoErr(),"error in arguments");
return (RETURN_ERROR);
}
if (lock = CreateDir (args.path))
{
UnLock (lock);
if (dob = GetDefDiskObject (WBGARBAGE))
{
if (PutDiskObject (args.path,dob))
rc = RETURN_OK;
else
PrintFault (IoErr(),"cannot save icon");
FreeDiskObject (dob);
}
else
PrintFault (IoErr(),"cannot obtain default icon");
}
else
PrintFault (IoErr(),"cannot create directory");
return (rc);
}
Re: Icon.library ?
OK i have a working CLI command that transforms some icontype in a WBTOOL type.
In fact i can define the type as a string argument in the commands template
Idid spot the following defines
<workbench/workbenvh.h>
#define WBDISK 1
#define WBDRAWER 2
#define WBTOOL 3
#define WBPROJECT 4
#define WBGARBAGE 5
#define WBDEVICE 6
#define WBKICK 7
#define WBAPPICON 8
How do i transform easily the icontype string to something
icon->do_Type = ???icontype??? ; accepts as well
as
icon->do_Type = WBTOOL
In fact i can define the type as a string argument in the commands template
Code: Select all
/* The icon to change should be in the current directory
*/
#define __USE_INLINE__ //always befor includes
#include <exec/types.h>
// #include <proto/intuition.h>
// #include <intuition/intuition.h>
#include <workbench/workbench.h>
#include <proto/icon.h>
#include <proto/dos.h> //PrintFault
//#include <stdio.h>
#include <string.h>
#define TEMPLATE "Icon/A,Type/A"
int main(int argc, char *argv[]) {
char iconname[31];
char icontype[10];
struct DiskObject *icon;
int rc = RETURN_FAIL;
struct RDArgs *rdargs;
LONG args[] = { 0, 0};
rdargs = ReadArgs(TEMPLATE,args, NULL);
if (rdargs == NULL){
PrintFault(IoErr(), NULL);
goto endprog;
}
if (args[0]) strncpy (iconname, (char *)args[0] , 30);
if (args[1]) strncpy (icontype, (char *)args[1], 10);
if ( icon = GetDiskObject(iconname)) {
Printf("iconname %s\n", iconname);
icon->do_Type = WBTOOL ; //icontype;
if ( PutDiskObject(iconname, icon))
rc = RETURN_OK;
else
PrintFault (IoErr(),"cannot save icon");
FreeDiskObject(icon);
}
else
PrintFault (IoErr(),"cannot save icon");
endprog:
return rc;
}
<workbench/workbenvh.h>
#define WBDISK 1
#define WBDRAWER 2
#define WBTOOL 3
#define WBPROJECT 4
#define WBGARBAGE 5
#define WBDEVICE 6
#define WBKICK 7
#define WBAPPICON 8
How do i transform easily the icontype string to something
icon->do_Type = ???icontype??? ; accepts as well
as
icon->do_Type = WBTOOL
Re: Icon.library ?
How about a simple string comparison?JosDuchIt wrote:How do i transform easily the icontype string to something
icon->do_Type = ???icontype??? ; accepts as well
as
icon->do_Type = WBTOOL
Re: Icon.library ?
@tboeckel
something like this below works OK, but i was wondering if there was nothing more elegant (for long list of #definded values) eg make an array of #defined string & its value.
As it must not be an uncommon situation I just hoped for this kind of solution, but OK it works.
something like this below works OK, but i was wondering if there was nothing more elegant (for long list of #definded values) eg make an array of #defined string & its value.
As it must not be an uncommon situation I just hoped for this kind of solution, but OK it works.
Code: Select all
if (!(strcmp("WBDISK", icontype)))
icon->do_Type = WBDISK ;
else if (!(strcmp("WBDRAWER", icontype)))
icon->do_Type = WBDRAWER ;
else if (!(strcmp("WBTOOL", icontype)))
icon->do_Type = WBTOOL ;
else if (!(strcmp("WBPROJECT", icontype)))
icon->do_Type = WBPROJECT;
else if (!(strcmp("WBDEVICE", icontype)))
icon->do_Type = WBDEVICE ;
else if (!(strcmp("WBKICK", icontype)))
icon->do_Type = WBDEVICE ;
else if (!(strcmp("APPICON", icontype)))
icon->do_Type = WBAPPICON;
- salass00
- AmigaOS Core Developer
- Posts: 534
- Joined: Sat Jun 18, 2011 4:12 pm
- Location: Finland
- Contact:
Re: Icon.library ?
Since the numbers are ordered 1 to 8 you could do it simply like this:
Alternately a version that doesn't rely on the values of the constants being 1 to 8 would look like so:
Note that strcmp() does case-sensitive string comparison (i.e. "WBDISK", "wbdisk" and "WbDisk" are not equal). If you want case-insensitive comparison (might make more sense if icontype string comes from user input) then you should use stricmp() or Stricmp() (utility.library function) instead.
Code: Select all
STATIC CONST CONST_STRPTR icontype_strings[] = {
"WBDISK",
"WBDRAWER",
"WBTOOL",
"WBPROJECT",
"WBGARBAGE",
"WBDEVICE",
"WBKICK",
"WBAPPICON",
NULL
};
int i;
for (i = 0; icontype_strings[i]; i++) {
if (!strcmp(icontype_strings[i], icontype)) {
icon->do_Type = i+1;
break;
}
}
Code: Select all
STATIC CONST CONST_STRPTR icontype_strings[] = {
"WBDISK",
"WBDRAWER",
"WBTOOL",
"WBPROJECT",
"WBGARBAGE",
"WBDEVICE",
"WBKICK",
"WBAPPICON",
NULL
};
STATIC CONST UBYTE icontype_values[] = {
WBDISK,
WBDRAWER,
WBTOOL,
WBPROJECT,
WBGARBAGE,
WBDEVICE,
WBKICK,
WBAPPICON
};
int i;
for (i = 0; icontype_strings[i]; i++) {
if (!strcmp(icontype_strings[i], icontype)) {
icon->do_Type = icontype_values[i];
break;
}
}