;/* sc link lib lib:debug.lib debug line getappdiskobject.c quit */ /* ** Example code on how to get the application icon (.info) ** ** Written by Harry "Piru" Sintonen ** Public Domain. ** */ #include #include #include #include #include extern struct WBStartup *_WBenchMsg; int main(void); struct DiskObject *GetAppDiskObject(void); int main(void) { struct DiskObject *dobj; dobj = GetAppDiskObject(); if (dobj) { printf("Got the application icon.\n"); FreeDiskObject(dobj); } else printf("Could not get the application icon.\n"); return 0; } #ifdef __MORPHOS__ #include struct DiskObject *GetAppDiskObject(void) { BPTR olddir; struct DiskObject *dobj; UBYTE *name; if (_WBenchMsg) { olddir = _WBenchMsg->sm_ArgList[0].wa_Lock; name = alloca(strlen(_WBenchMsg->sm_ArgList[0].wa_Name) + 1); strcpy(name, _WBenchMsg->sm_ArgList[0].wa_Name); } else { struct CommandLineInterface *cli = Cli(); const UBYTE *progname = BADDR(cli->cli_CommandName); ULONG len; olddir = GetProgramDir(); len = *progname++; if (len) { const UBYTE *ptr = progname + len - 1; while (*ptr != ':' && *ptr != '/' && ptr != progname) ptr--; if (*ptr == ':' || *ptr == '/') ptr++; len = progname + len - ptr; name = alloca(len + 1); memcpy(name, ptr, len); name[len] = '\0'; } else name = NULL; } if (name) { olddir = CurrentDir(olddir); dobj = GetDiskObject(name); if (!dobj) { int len = strlen(name); if (len > 4 && !strcasecmp(".elf", &name[len - 4])) { name[len - 4] = '\0'; dobj = GetDiskObject(name); } } CurrentDir(olddir); } else dobj = NULL; return dobj; } #else /* __MORPHOS__ */ struct DiskObject *GetAppDiskObject(void) { BPTR olddir; struct DiskObject *dobj; if (_WBenchMsg) { olddir = CurrentDir(_WBenchMsg->sm_ArgList[0].wa_Lock); dobj = GetDiskObject(_WBenchMsg->sm_ArgList[0].wa_Name); } else { UBYTE buf[256]; olddir = CurrentDir(GetProgramDir()); if (GetProgramName(buf, sizeof(buf))) dobj = GetDiskObject(FilePart(buf)); else dobj = NULL; } CurrentDir(olddir); return dobj; } #endif /* __MORPHOS__ */