;/* 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__ struct DiskObject *GetAppDiskObject(void) { BPTR olddir; struct DiskObject *dobj; UBYTE buf[256], *name; if (_WBenchMsg) { olddir = _WBenchMsg->sm_ArgList[0].wa_Lock; strncpy(buf, _WBenchMsg->sm_ArgList[0].wa_Name, sizeof(buf) - 1); buf[sizeof(buf) - 1] = '\0'; name = buf; } else { olddir = GetProgramDir(); if (GetProgramName(buf, sizeof(buf))) name = FilePart(buf); 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__ */