Icon.library ?

This forum is for general developer support questions.
Post Reply
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 6:47 pm
Contact:

Icon.library ?

Post by JosDuchIt »

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 ?
User avatar
tboeckel
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 68
Joined: Mon Jun 20, 2011 9:56 am
Contact:

Re: Icon.library ?

Post by tboeckel »

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 ?
Basically it is something like this to change the icon type of "disk.info" from whatever to a tool icon:

Code: Select all

icon = GetDiskObject("disk");
icon->do_Type = WBTOOL;
PutDiskObject("disk", icon);
FreeDiskObject(icon);
Getting the icon type is left to you as an excercise ;)

If you need to do more complex operations on the icon then perhaps GetIconTags() and PutIconTags() are more suitable functions.
User avatar
thomasrapp
Posts: 318
Joined: Sun Jun 19, 2011 12:22 am

Re: Icon.library ?

Post by thomasrapp »

Turning a disk.info into a tool will hide the partition...
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 6:47 pm
Contact:

Re: Icon.library ?

Post by JosDuchIt »

Thanks, also for the warning.

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
User avatar
thomasrapp
Posts: 318
Joined: Sun Jun 19, 2011 12:22 am

Re: Icon.library ?

Post by thomasrapp »

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);
}
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 6:47 pm
Contact:

Re: Icon.library ?

Post by JosDuchIt »

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

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;

}
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
User avatar
tboeckel
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 68
Joined: Mon Jun 20, 2011 9:56 am
Contact:

Re: Icon.library ?

Post by tboeckel »

JosDuchIt wrote:How do i transform easily the icontype string to something
icon->do_Type = ???icontype??? ; accepts as well

as

icon->do_Type = WBTOOL
How about a simple string comparison?
JosDuchIt
Posts: 291
Joined: Sun Jun 26, 2011 6:47 pm
Contact:

Re: Icon.library ?

Post by JosDuchIt »

@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.

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;
			
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 534
Joined: Sat Jun 18, 2011 4:12 pm
Location: Finland
Contact:

Re: Icon.library ?

Post by salass00 »

Since the numbers are ordered 1 to 8 you could do it simply like this:

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;
	}
}
Alternately a version that doesn't rely on the values of the constants being 1 to 8 would look like so:

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;
	}
}
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.
Post Reply