1
0
mirror of https://github.com/krustur/IconSnap.git synced 2025-11-20 16:29:35 +00:00

Reading WB tooltype args

This commit is contained in:
krustur
2018-12-15 14:44:41 +01:00
parent 2b76e490f1
commit 3d29d360bc
5 changed files with 248 additions and 126 deletions

View File

@ -26,7 +26,8 @@
"unistd.h": "c", "unistd.h": "c",
"intuition.h": "c", "intuition.h": "c",
"signal.h": "c", "signal.h": "c",
"exec_sysbase_pragmas.h": "c" "exec_sysbase_pragmas.h": "c",
"execbase.h": "c"
} }
} }
} }

Binary file not shown.

View File

@ -19,11 +19,14 @@
#include "sys.h" #include "sys.h"
#include <exec/execbase.h>
// TODO: Scripted tests! // TODO: Scripted tests!
// C helpers // Helpers
#define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y))
#define ZERO (0L)
// Version tag // Version tag
#define VERSTAG "\0$VER: IconSnap 0.3 (30.11.2018)" #define VERSTAG "\0$VER: IconSnap 0.3 (30.11.2018)"
@ -76,7 +79,8 @@ unsigned char *AlignIconFixedDiskObjectName = NULL;
unsigned int AlignCurrentWorkingDir(); unsigned int AlignCurrentWorkingDir();
unsigned int AlignDir(unsigned char *diskObjectName); unsigned int AlignDir(unsigned char *diskObjectName);
unsigned int AlignIcon(unsigned char *diskObjectName); unsigned int AlignFile(unsigned char *diskObjectName);
unsigned int AlignDiskObject(struct DiskObject *diskObject, long iconWidth, long iconHeigth);
long Align(long orig, long pad, long align, long alignoffset); long Align(long orig, long pad, long align, long alignoffset);
int main(int argc, char **argv) int main(int argc, char **argv)
@ -91,13 +95,109 @@ int main(int argc, char **argv)
if (argc == 0) if (argc == 0)
{ {
//Opened from WB // Opened from WB
Information("Started from Workbench\n"); Information("Started from Workbench\n");
exit(RETURN_OK);
} // Read args from tooltip
else struct WBStartup *wbStartup = (struct WBStartup *)argv;
struct WBArg iconSnap = wbStartup->sm_ArgList[0];
if (iconSnap.wa_Lock != ZERO)
{ {
Verbose("Started from CLI\n"); BPTR oldDir = CurrentDir(iconSnap.wa_Lock);
struct DiskObject *iconSnapDiskObject = GetDiskObjectNew(iconSnap.wa_Name);
if (iconSnapDiskObject != NULL)
{
STRPTR VerboseTT = FindToolType(iconSnapDiskObject->do_ToolTypes, "VERBOSE");
if (VerboseTT)
{
SysSetVerboseEnabled(TRUE);
}
STRPTR ConsoleDelayTT = FindToolType(iconSnapDiskObject->do_ToolTypes, "CONSOLEDELAY");
if (ConsoleDelayTT)
{
long consoleDelay = strtol(ConsoleDelayTT, NULL, 10);
SysSetConsoleDelay(consoleDelay);
}
STRPTR PadLeftTT = FindToolType(iconSnapDiskObject->do_ToolTypes, "PADLEFT");
if (PadLeftTT)
{
// Information("PadLeftTT: %s\n", PadLeftTT);
PaddingLeft = strtol(PadLeftTT, NULL, 10);
}
STRPTR PadTopTT = FindToolType(iconSnapDiskObject->do_ToolTypes, "PADTOP");
if (PadTopTT)
{
// Information("PadTopTT: %s\n", PadTopTT);
PaddingTop = strtol(PadTopTT, NULL, 10);
}
STRPTR AlignXTT = FindToolType(iconSnapDiskObject->do_ToolTypes, "ALIGNX");
if (AlignXTT)
{
Information("AlignXTT: %s\n", AlignXTT);
AlignX = strtol(AlignXTT, NULL, 10);
}
STRPTR AlignYTT = FindToolType(iconSnapDiskObject->do_ToolTypes, "ALIGNY");
if (AlignYTT)
{
Information("AlignYTT: %s\n", AlignYTT);
AlignY = strtol(AlignYTT, NULL, 10);
}
STRPTR CenterXTT = FindToolType(iconSnapDiskObject->do_ToolTypes, "CENTERX");
if (CenterXTT)
{
CenterX = TRUE;
}
STRPTR BottomYTT = FindToolType(iconSnapDiskObject->do_ToolTypes, "BOTTOMY");
if (BottomYTT)
{
BottomY = TRUE;
}
}
CurrentDir(oldDir);
Verbose(" PADLEFT %li\n", PaddingLeft);
Verbose(" PADTOP %li\n", PaddingTop);
Verbose(" ALIGNX %li\n", AlignX);
Verbose(" ALIGNY %li\n", AlignY);
Verbose(" CENTERX %hi\n", CenterX);
Verbose(" BOTTOMY %hi\n", BottomY);
}
// No tools selected?
// Iterate parameters
LONG numArgs = wbStartup->sm_NumArgs;
Verbose("Number of arguments received = %ld\n", numArgs);
// for (LONG i = 0; i < numArgs; i++)
// {
//Verbose("Argument %ld name = %s\n", i, wbStartup->sm_ArgList[i].wa_Name);
// if (wbStartup->sm_ArgList[0].wa_Lock != ZERO)
// {
// BPTR oldDir = CurrentDir(wbStartup->sm_ArgList[0].wa_Lock);
// struct DiskObject *dobj;
// dobj = GetDiskObjectNew(wbStartup->sm_ArgList[i].wa_Name);
// if (dobj != NULL)
// {
// Information("Opened disk object.\n");
// STRPTR TTarg = NULL;
// TTarg = FindToolType(dobj->do_ToolTypes, "TEST");
// if (TTarg)
// {
// Verbose(" TEST found set to = >%s<\n", TTarg);
// }
// }
// CurrentDir(oldDir);
// }
// Verbose("");
// }
exit(RETURN_OK);
} }
// check arguments // check arguments
@ -180,7 +280,7 @@ int main(int argc, char **argv)
} }
else if (fileOption) else if (fileOption)
{ {
fixCount = AlignIcon(fileOption); fixCount = AlignFile(fileOption);
} }
else if (dirOption) else if (dirOption)
{ {
@ -325,7 +425,7 @@ unsigned int AlignDir(unsigned char *dirName)
if (StringEndsWith(AlignDirFullPath, ".info")) if (StringEndsWith(AlignDirFullPath, ".info"))
{ {
// Verbose("AlignDirFullPath: %s\n", AlignDirFullPath); // Verbose("AlignDirFullPath: %s\n", AlignDirFullPath);
fixCount += AlignIcon(AlignDirFullPath); fixCount += AlignFile(AlignDirFullPath);
} }
} }
//printf("%s\n", direntry->d_name); //printf("%s\n", direntry->d_name);
@ -335,7 +435,7 @@ unsigned int AlignDir(unsigned char *dirName)
return fixCount; return fixCount;
} }
unsigned int AlignIcon(unsigned char *diskObjectName) unsigned int AlignFile(unsigned char *diskObjectName)
{ {
unsigned long diskObjectNameLen = strlen(diskObjectName); unsigned long diskObjectNameLen = strlen(diskObjectName);
// unsigned char *fixedDiskObjectName = malloc(PATH_MAX); // unsigned char *fixedDiskObjectName = malloc(PATH_MAX);
@ -366,6 +466,14 @@ unsigned int AlignIcon(unsigned char *diskObjectName)
} }
if (diskObject) if (diskObject)
{ {
return AlignDiskObject(diskObject, iconWidth, iconHeigth);
}
Verbose("Skipped \"%s\" - icon not found\n", AlignIconFixedDiskObjectName);
return 0;
}
unsigned int AlignDiskObject(struct DiskObject *diskObject, long iconWidth, long iconHeigth)
{
// Verbose("do_Magic: %x\n", diskObject->do_Magic); // Verbose("do_Magic: %x\n", diskObject->do_Magic);
// Verbose(" Version: %hi\n", diskObject->do_Version); // Verbose(" Version: %hi\n", diskObject->do_Version);
// Verbose(" do_Type: %i\n", (int)diskObject->do_Type); // Verbose(" do_Type: %i\n", (int)diskObject->do_Type);
@ -474,9 +582,6 @@ unsigned int AlignIcon(unsigned char *diskObjectName)
origx, origy, origx, origy,
newx, newy); newx, newy);
return 1; return 1;
}
Verbose("Skipped \"%s\" - icon not found\n", AlignIconFixedDiskObjectName);
return 0;
} }
long Align(long orig, long pad, long align, long alignoffset) long Align(long orig, long pad, long align, long alignoffset)

View File

@ -34,6 +34,9 @@ short iconLibraryV44Enabled = FALSE;
// Logging // Logging
#define LOG_MAX (256) #define LOG_MAX (256)
// const char *ConsoleString = "CON:20/20/500/100/IconSnap/CLOSE";
const char *ConsoleString = "CON:20/20/500/100/IconSnap";
long ConsoleDelay = 100;
unsigned char *LogBuffer = NULL; unsigned char *LogBuffer = NULL;
short verbose = FALSE; short verbose = FALSE;
BPTR wbcon = (BPTR)NULL; BPTR wbcon = (BPTR)NULL;
@ -70,7 +73,7 @@ short SysInit(int argc, char **argv)
if (argc == 0) if (argc == 0)
{ {
//Opened from WB //Opened from WB
wbcon = Open("CON:20/20/500/100/IconSnap", MODE_NEWFILE); wbcon = Open(ConsoleString, MODE_NEWFILE);
SelectOutput(wbcon); SelectOutput(wbcon);
} }
@ -87,7 +90,7 @@ void SysCleanup(void)
} }
if (wbcon != (BPTR)NULL) if (wbcon != (BPTR)NULL)
{ {
Delay(100); Delay(ConsoleDelay);
Close(wbcon); Close(wbcon);
} }
if (DosBase != NULL) if (DosBase != NULL)
@ -117,6 +120,12 @@ void SysSetVerboseEnabled(short enabled)
} }
} }
void SysSetConsoleDelay(long delay)
{
Verbose("ConsoleDelay changed from %li to %li\n", ConsoleDelay, delay);
ConsoleDelay = delay;
}
// Logging // Logging
void Verbose(const char *fmt, ...) void Verbose(const char *fmt, ...)
{ {
@ -124,9 +133,15 @@ void Verbose(const char *fmt, ...)
return; return;
va_list args; va_list args;
// va_start(args, fmt); va_start(args, fmt);
Information(fmt, args); vsnprintf(LogBuffer, LOG_MAX-1, fmt, args);
// va_end(args); Write(Output(), LogBuffer, strlen(LogBuffer));
va_end(args);
// va_list args;
// // va_start(args, fmt);
// Information(fmt, args);
// // va_end(args);
} }
void Information(const char *fmt, ...) void Information(const char *fmt, ...)

View File

@ -10,5 +10,6 @@ void SysSetVerboseEnabled(short enabled);
// Logging // Logging
void Information(const char *fmt, ...); void Information(const char *fmt, ...);
void Verbose(const char *fmt, ...); void Verbose(const char *fmt, ...);
void SysSetConsoleDelay(long delay);
#endif /* SYS_H */ #endif /* SYS_H */