/trunk/CHANGELOG.md |
---|
1,7 → 1,9 |
# Changelog |
## 1.7.0.22 [Work-In-Progress] |
- Simplified source code (expressions, slider names, etc. are now loaded directly in the PARM resource). |
- Simplified source code: |
* expressions, slider names, etc. are now loaded directly in the PARM resource). |
* Load-methods don't return boolean and a reason string. Instead they return 0 (success) or a error message ID otherwise. |
- As side effect: The slider positions will be preserved when a filter is made |
## 1.7.0.21 [23-Nov-2023] |
/trunk/ff.h |
---|
112,6 → 112,8 |
extern int tokpos,tokstart,varused[]; |
extern TCHAR *errstr; |
typedef int FFLoadingResult; |
//#define DEBUG |
typedef struct InternalState_ { |
132,16 → 134,16 |
void parm_cleanup(); |
// from read.c |
Boolean readparams_afs_pff(Handle h, TCHAR**reason); |
FFLoadingResult readparams_afs_pff(Handle h); |
void convert_premiere_to_photoshop(PARM_T* photoshop, PARM_T_PREMIERE* premiere); |
Boolean readfile_8bf(StandardFileReply *sfr, TCHAR**reason); |
FFLoadingResult readfile_8bf(StandardFileReply *sfr); |
Handle readfileintohandle(FILEREF r); |
Boolean readfile_afs_pff(StandardFileReply* sfr, TCHAR** reason); |
Boolean readfile_ffl(StandardFileReply* sfr, TCHAR** reason); |
Boolean readfile_ffx(StandardFileReply* sfr, TCHAR** reason); |
Boolean readfile_picotxt_or_ffdecomp(StandardFileReply* sfr, TCHAR** reason); |
Boolean readfile_guf(StandardFileReply* sfr, TCHAR** reason); |
Boolean readPARM(PARM_T* parm,Ptr h); |
FFLoadingResult readfile_afs_pff(StandardFileReply* sfr); |
FFLoadingResult readfile_ffl(StandardFileReply* sfr); |
FFLoadingResult readfile_ffx(StandardFileReply* sfr); |
FFLoadingResult readfile_picotxt_or_ffdecomp(StandardFileReply* sfr); |
FFLoadingResult readfile_guf(StandardFileReply* sfr); |
FFLoadingResult readPARM(PARM_T* parm,Ptr h); |
// from save.c |
OSErr saveparams_afs_pff(Handle h); |
178,8 → 180,8 |
void deobfusc(PARM_T* pparm); |
// from loadfile_*.c |
Boolean loadfile(StandardFileReply *sfr, TCHAR**reason); |
Boolean readPARMresource(HMODULE hm, TCHAR**reason); |
FFLoadingResult loadfile(StandardFileReply *sfr); |
FFLoadingResult readPARMresource(HMODULE hm); |
// from main.c |
int64_t maxspace(void); |
/trunk/language.h |
---|
272,6 → 272,10 |
#define MSG_FFL_CONVERTED_ENUS "FFL file converted to TXT files. You can now open these TXT files." |
#define MSG_FFL_CONVERTED_DEDE "FFL Datei wurde in TXT Dateien extrahiert. Sie können diese TXT Dateien nun öffnen." |
// TODO: Give own IDs and Translate |
#define MSG_OUT_OF_MEMORY_ID 14 |
#define MSG_INVALID_FILE_SIGNATURE_ID 6 |
void strcpy_advance_id(TCHAR** str, int msgid); |
int FF_GetMsg(TCHAR* ret, int MsgId); |
TCHAR* FF_GetMsg_Cpy(int MsgId); |
/trunk/load_mac.c |
---|
24,8 → 24,8 |
#include "file_compat.h" |
Boolean readPARMresource(HMODULE hm,char **reason){ |
Boolean res = false; |
FFLoadingResult readPARMresource(HMODULE hm){ |
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
Handle h; |
if( (h = Get1Resource(PARM_TYPE,PARM_ID_NEW)) || |
33,7 → 33,7 |
{ |
HLock(h); |
if(GetHandleSize(h) == sizeof(PARM_T)) { |
res = readPARM(*h, &gdata->parm, reason, 0 /*Mac format resource*/); |
res = readPARM(&gdata->parm, *h, 0 /*Mac format resource*/); |
gdata->obfusc = false; |
ReleaseResource(h); |
} else { |
40,7 → 40,7 |
// PARM has wrong size. Should not happen |
gdata->obfusc = false; |
ReleaseResource(h); |
return false; |
return MSG_INVALID_FILE_SIGNATURE_ID; |
} |
} |
else if( ((h = Get1Resource(OBFUSCDATA_TYPE_NEW,OBFUSCDATA_ID_NEW)) || |
49,7 → 49,7 |
HLock(h); |
if(GetHandleSize(h) == sizeof(PARM_T)) { |
deobfusc((PARM_T*)*h); |
res = readPARM(*h, &gdata->parm, reason, 0 /*Mac format resource*/); |
res = readPARM(&gdata->parm, *h, 0 /*Mac format resource*/); |
gdata->obfusc = true; |
ReleaseResource(h); |
} else { |
56,7 → 56,7 |
// Obfuscated PARM has wrong size. Should not happen |
gdata->obfusc = false; |
ReleaseResource(h); |
return false; |
return MSG_INCOMPATIBLE_OBFUSCATION_ID; |
} |
} |
if (!res) { |
65,78 → 65,74 |
return res; |
} |
static Boolean readmacplugin(StandardFileReply *sfr,char **reason){ |
Boolean res = false; |
FFLoadingResult Boolean readmacplugin(StandardFileReply *sfr){ |
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
short rrn = FSpOpenResFile(&sfr->sfFile,fsRdPerm); |
if(rrn != -1){ |
if(readPARMresource(NULL,reason)) |
res = true; |
res = readPARMresource(NULL); |
CloseResFile(rrn); |
}else |
*reason = "Could not open file."; |
} |
else |
res = MSG_CANNOT_OPEN_FILE_ID; |
return res; |
} |
Boolean loadfile(StandardFileReply *sfr,char **reason){ |
FFLoadingResult loadfile(StandardFileReply *sfr){ |
Boolean readok = false; |
FInfo fndrInfo; |
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
// The different read-functions will return true if the resource was successfully loaded, |
// or false otherwise. If *reason is set, then the answer is clearly "No". If the result |
// is just false, it means that the program should continue with the next read-function. |
*reason = NULL; |
if(FSpGetFInfo(&sfr->sfFile,&fndrInfo) == noErr){ |
// first try to read text parameters (AFS, TXT, PFF) |
if (*reason == NULL) { |
if (readfile_afs_pff(sfr,reason)) { |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = readfile_afs_pff(sfr))) { |
parm_reset(true, false, true, false); |
gdata->obfusc = false; |
return true; |
return 0; |
} |
} |
// Try to read the file as FFL file |
if (*reason == NULL) { |
if (readfile_ffl(sfr,reason)) { |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = (readfile_ffl(sfr)))) { |
parm_reset(true, true, true, true); |
gdata->obfusc = false; |
return true; |
return 0; |
} |
} |
// then try "Filters Unlimited" file (FFX) |
if (*reason == NULL) { |
if (readfile_ffx(sfr,reason)) { |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = (readfile_ffx(sfr)))) { |
gdata->obfusc = false; |
return true; |
return 0; |
} |
} |
// then try "PluginCommander TXT" file (TXT) |
if (*reason == NULL) { |
if (readfile_picotxt(sfr,reason)) { |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = (readfile_picotxt(sfr)))) { |
gdata->obfusc = false; |
return true; |
return 0; |
} |
} |
// Is it a "GIMP UserFilter (GUF)" file? (Only partially compatible with Filter Factory!!!) |
if (*reason == NULL) { |
if (readfile_guf(sfr,reason)) { |
return true; |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = (readfile_guf(sfr)))) { |
return 0; |
} |
} |
// Try Mac plugin resource |
if (*reason == NULL) { |
if (readmacplugin(sfr,reason)) { |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = (readmacplugin(sfr)))) { |
if (gdata->parm.iProtected) { |
parm_reset(true, true, true, true); |
*reason = "The filter is protected."; |
res = MSG_FILTER_PROTECTED_ID; |
} else { |
return true; |
return 0; |
} |
} |
} |
143,25 → 139,19 |
// Try Windows resources (we need to do a binary scan) |
// Note that we cannot detect obfuscated filters here! |
if (*reason == NULL) { |
if (readfile_8bf(sfr,reason)) { |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = (readfile_8bf(sfr)))) { |
if (gdata->parm.iProtected) { |
parm_reset(true, true, true, true); |
*reason = "The filter is protected."; |
res = MSG_FILTER_PROTECTED_ID; |
} else { |
return true; |
return 0; |
} |
} |
} |
// We didn't had success. If we have a clear reason, return false and the reason. |
// If we don't have a clear reason, set a generic reason and return false. |
if (*reason == NULL) { |
*reason = "It is not a text parameter file, nor a standalone Mac/PC filter created by Filter Factory/Filter Foundry."; |
} |
return false; |
return res; |
} else { |
*reason = "File cannot be opened"; |
return false; |
return MSG_CANNOT_OPEN_FILE_ID; |
} |
} |
/trunk/load_win.c |
---|
38,7 → 38,7 |
else return true; |
} |
Boolean readPARMresource(HMODULE hm, TCHAR** reason) { |
FFLoadingResult readPARMresource(HMODULE hm) { |
HRSRC resinfo; |
HANDLE h; |
Ptr pparm; |
49,7 → 49,7 |
// load first PARM resource |
if ((resinfo = FindResource(hm, MAKEINTRESOURCE(parm_id), PARM_TYPE))) { |
if ((h = LoadResource(hm, resinfo)) && (pparm = (Ptr)LockResource(h))) { |
Boolean res = readPARM(&gdata->parm, pparm); |
FFLoadingResult res = readPARM(&gdata->parm, pparm); |
gdata->obfusc = false; |
return res; |
} |
62,15 → 62,12 |
// We need to copy the information, because the resource data is read-only |
DWORD resSize = SizeofResource(hm, resinfo); |
if (resSize == sizeof(PARM_T)) { |
Boolean res; |
FFLoadingResult res; |
PARM_T* copy = (PARM_T*)malloc(resSize); |
if (!copy) return false; |
if (!copy) return MSG_OUT_OF_MEMORY_ID; |
memcpy(copy, pparm, resSize); |
deobfusc(copy); |
res = readPARM(&gdata->parm, (Ptr)copy); |
if (!res) { |
if (reason) *reason = FF_GetMsg_Cpy(MSG_INCOMPATIBLE_OBFUSCATION_ID); |
} |
free(copy); |
gdata->obfusc = true; |
return res; |
78,52 → 75,47 |
else { |
// Obfuscationed PARM has wrong size. It is probably a file with different RCDATA |
gdata->obfusc = false; |
return false; |
return MSG_INVALID_PARAMETER_DATA_ID; |
} |
} |
} |
return false; |
return MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
} |
Boolean loadfile(StandardFileReply* sfr, TCHAR** reason) { |
FFLoadingResult loadfile(StandardFileReply* sfr) { |
HMODULE hm; |
TCHAR* reasonstr; |
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
// The different read-functions will return true if the resource was successfully loaded, |
// or false otherwise. If *reason is set, then the answer is clearly "No". If the result |
// is just false, it means that the program should continue with the next read-function. |
reasonstr = NULL; |
// First, try to read the file as AFS/PFF/TXT file |
if (reasonstr == NULL) { |
if (readfile_afs_pff(sfr, &reasonstr)) { |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = readfile_afs_pff(sfr))) { |
gdata->obfusc = false; |
parm_reset(true, false, true, false); |
return true; |
return 0; |
} |
} |
// Try to read the file as FFL file |
if (reasonstr == NULL) { |
if (readfile_ffl(sfr, &reasonstr)) { |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = readfile_ffl(sfr))) { |
gdata->obfusc = false; |
parm_reset(true, true, true, true); |
return true; |
return 0; |
} |
} |
// If that didn't work, try to load as Windows image file (Resource API for 8BF/PRM files) |
if (reasonstr == NULL) { |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (hm = LoadLibraryEx(sfr->sfFile.szName, NULL, LOAD_LIBRARY_AS_DATAFILE)) { |
if (readPARMresource(hm, &reasonstr)) { |
if (0 == (res = readPARMresource(hm))) { |
gdata->parm.standalone = false; // just because the loaded file is standalone, does not mean that WE are standalone |
if (gdata->parm.iProtected) { |
parm_reset(true, true, true, true); |
reasonstr = FF_GetMsg_Cpy(MSG_FILTER_PROTECTED_ID); |
res = MSG_FILTER_PROTECTED_ID; |
} |
else { |
FreeLibrary(hm); |
return true; |
return 0; |
} |
} |
FreeLibrary(hm); |
131,48 → 123,40 |
} |
// Is it a "Filters Unlimited" FFX filter? (Only partially compatible with Filter Factory!!!) |
if (reasonstr == NULL) { |
if (readfile_ffx(sfr, &reasonstr)) { |
return true; |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = readfile_ffx(sfr))) { |
return 0; |
} |
} |
// Is it a "Filters Unlimited" TXT filter? (Only partially compatible with Filter Factory!!!) |
if (reasonstr == NULL) { |
if (readfile_picotxt_or_ffdecomp(sfr, &reasonstr)) { |
return true; |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = readfile_picotxt_or_ffdecomp(sfr))) { |
return 0; |
} |
} |
// Is it a "GIMP UserFilter (GUF)" file? (Only partially compatible with Filter Factory!!!) |
if (reasonstr == NULL) { |
if (readfile_guf(sfr, &reasonstr)) { |
return true; |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = readfile_guf(sfr))) { |
return 0; |
} |
} |
// If nothing worked, we will try to find a PARM resource (MacOS plugin, or 64 bit 8BF on Win32 OS) |
// Note that we cannot detect obfuscated filters here! |
if (reasonstr == NULL) { |
if (readfile_8bf(sfr, &reasonstr)) { |
if (res == MSG_LOADFILE_UNKNOWN_FORMAT_ID) { |
if (0 == (res = readfile_8bf(sfr))) { |
if (gdata->parm.iProtected) { |
// This is for purely protected filters before the time when obfuscation and protection was merged |
parm_reset(true, true, true, true); |
reasonstr = FF_GetMsg_Cpy(MSG_FILTER_PROTECTED_ID); |
res = MSG_FILTER_PROTECTED_ID; |
} |
else { |
return true; |
return 0; |
} |
} |
} |
// We didn't had success. If we have a clear reason, return false and the reason. |
// If we don't have a clear reason, set a generic reason and return false. |
if (reasonstr == NULL) { |
reasonstr = FF_GetMsg_Cpy(MSG_LOADFILE_UNKNOWN_FORMAT_ID); |
} |
if (reason) *reason = reasonstr; |
return false; |
return res; |
} |
/trunk/main.c |
---|
332,7 → 332,7 |
gdata = (globals_t*)malloc(sizeof(globals_t)); |
if (!gdata) break; |
gdata->hWndMainDlg = (HWND)((PlatformData*)((AboutRecordPtr)pb)->platformData)->hwnd; // so that simplealert() works |
parmReadOk = readPARMresource((HMODULE)hDllInstance, NULL); |
parmReadOk = (0 == readPARMresource((HMODULE)hDllInstance)); |
if (!parmReadOk) gdata->parm.standalone = false; |
if (parmReadOk && (gdata->parm.cbSize != PARM_SIZE) && (gdata->parm.cbSize != PARM_SIZE_PREMIERE) && (gdata->parm.cbSize != PARM_SIG_MAC)) { |
parm_reset(true, true, true, true); |
566,7 → 566,7 |
sfr.sfReplacing = true; |
sfr.sfType = PS_FILTER_FILETYPE; |
parmReadOk = readPARMresource((HMODULE)hDllInstance, NULL); |
parmReadOk = (0 == readPARMresource((HMODULE)hDllInstance)); |
if (!parmReadOk) gdata->parm.standalone = false; |
if (parmReadOk && (gdata->parm.cbSize != PARM_SIZE) && (gdata->parm.cbSize != PARM_SIZE_PREMIERE) && (gdata->parm.cbSize != PARM_SIG_MAC)) { |
parm_reset(true, true, true, true); |
591,7 → 591,7 |
tmpState = saveInternalState(); |
} |
if (loadfile(&sfr, NULL)) { |
if (0 == loadfile(&sfr)) { |
if (parmReadOk) { |
// In the standalone filter, we only want the parameters (ctl,map) in the temporary .afs file, not the formulas |
// We do not need to care about the metadata, because the AFS does not touch the metadata anyway |
608,7 → 608,7 |
} |
} |
if( (bUninitializedParams = !(params && readparams_afs_pff(params, NULL))) ){ |
if( (bUninitializedParams = !(params && (0 == readparams_afs_pff(params)))) ){ |
/* either the parameter handle was uninitialised, |
or the parameter data couldn't be read; set default values */ |
615,7 → 615,7 |
Boolean parmReadOk; |
// see if saved parameters exist |
parmReadOk = readPARMresource((HMODULE)hDllInstance, NULL); |
parmReadOk = (0 == readPARMresource((HMODULE)hDllInstance)); |
if (!parmReadOk) gdata->parm.standalone = false; |
if (parmReadOk && (gdata->parm.cbSize != PARM_SIZE) && (gdata->parm.cbSize != PARM_SIZE_PREMIERE) && (gdata->parm.cbSize != PARM_SIG_MAC)) { |
parm_reset(true, true, true, true); |
/trunk/read.c |
---|
36,8 → 36,8 |
#define BUFSIZE 4L<<10 |
#define MAXLINE 0x200 |
Boolean readparams_afs_pff(Handle h, TCHAR**reason){ |
Boolean res = false; |
FFLoadingResult readparams_afs_pff(Handle h){ |
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
char linebuf[MAXLINE] = { 0 }; |
char curexpr[MAXEXPR] = { 0 }; |
char *p, *dataend, *q; |
44,7 → 44,7 |
char c; |
int linecnt, lineptr, exprcnt; |
if (!h) return false; |
//if (!h) return nilHandleErr; |
p = PILOCKHANDLE(h,false); |
dataend = p + PIGETHANDLESIZE(h); |
67,8 → 67,8 |
/* process complete line */ |
if(linecnt==0){ |
if(strcmp(linebuf,"%RGB-1.0") != 0){ |
// Note: We don't set *reason, because we cannot be sure if it is a valid file in regards to a different data type |
// We only set *Reason, if we are sure that it is an AFS file which is indeed wrong. |
// Note: We don't set res to an error message, because we cannot be sure if it is a valid file in regards to a different data type |
// We only set res to an error message, if we are sure that it is an AFS file which is indeed wrong. |
break; |
} |
}else if(linecnt<=8){ |
81,7 → 81,7 |
if(lineptr){ |
/* it's not an empty line; append it to current expr string */ |
if( (q-curexpr) + lineptr >= MAXEXPR) { |
if (reason) *reason = FF_GetMsg_Cpy(MSG_EXPRESSION1024_FOUND_ID); |
res = MSG_EXPRESSION1024_FOUND_ID; |
break; |
} |
q = cat(q,linebuf); |
91,7 → 91,7 |
strcpy(gdata->parm.szFormula[exprcnt], curexpr); |
if(++exprcnt == 4){ |
res = true; |
res = 0; |
break; /* got everything we want */ |
} |
187,9 → 187,9 |
return val; |
} |
Boolean readfile_ffx(StandardFileReply* sfr, TCHAR** reason) { |
FFLoadingResult readfile_ffx(StandardFileReply* sfr) { |
Handle h; |
Boolean res = false; |
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
FILEREF refnum; |
uint32_t len; |
char* val; |
196,8 → 196,6 |
int format_version = -1; |
int i; |
UNREFERENCED_PARAMETER(reason); |
if (FSpOpenDF(&sfr->sfFile, fsRdPerm, &refnum) == noErr) { |
if ((h = readfileintohandle(refnum))) { |
char* q = (char*)PILOCKHANDLE(h, false); |
315,7 → 313,7 |
strcpy(gdata->parm.szMap[2], "Map 2:"); |
strcpy(gdata->parm.szMap[3], "Map 3:"); |
res = true; |
res = 0; |
} |
} |
PIDISPOSEHANDLE(h); |
327,11 → 325,11 |
return res; |
} |
Boolean readfile_8bf(StandardFileReply *sfr, TCHAR**reason){ |
FFLoadingResult readfile_8bf(StandardFileReply *sfr){ |
unsigned char magic[2]; |
FILECOUNT count; |
Handle h; |
Boolean res = false; |
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
FILEREF refnum; |
if(FSpOpenDF(&sfr->sfFile,fsRdPerm,&refnum) == noErr){ |
356,13 → 354,13 |
} // else no point in proceeding |
FSClose(refnum); |
}else |
if (reason) *reason = FF_GetMsg_Cpy(MSG_CANNOT_OPEN_FILE_ID); |
res = MSG_CANNOT_OPEN_FILE_ID; |
if (res) gdata->obfusc = false; |
return res; |
} |
Boolean readPARM(PARM_T* pparm, Ptr p){ |
FFLoadingResult readPARM(PARM_T* pparm, Ptr p){ |
Boolean towin, tomac, fromwin, frommac; |
unsigned int signature = *((unsigned int*)p); |
unsigned int standalone = *((unsigned int*)p+1); |
391,7 → 389,7 |
// Is it a valid signature? |
if (!fromwin && !frommac) { |
// No valid signature found |
return false; |
return MSG_INVALID_FILE_SIGNATURE_ID; |
} |
// Does it come from Premiere or Photoshop? |
469,7 → 467,7 |
pparm->val[i] = EndianS32_LtoN(pparm->val[i]); |
} |
return true; |
return 0; |
} |
Handle readfileintohandle(FILEREF r){ |
687,15 → 685,13 |
return true; |
} |
Boolean readfile_picotxt_or_ffdecomp(StandardFileReply* sfr, TCHAR** reason) { |
FFLoadingResult readfile_picotxt_or_ffdecomp(StandardFileReply* sfr) { |
Handle h; |
Boolean res = false; |
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
FILEREF refnum; |
UNREFERENCED_PARAMETER(reason); |
if (!fileHasExtension(sfr, TEXT(".txt"))) return MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
if (!fileHasExtension(sfr, TEXT(".txt"))) return false; |
if (FSpOpenDF(&sfr->sfFile, fsRdPerm, &refnum) == noErr) { |
if ((h = readfileintohandle(refnum))) { |
FILECOUNT count = (FILECOUNT)PIGETHANDLESIZE(h); |
755,7 → 751,7 |
} |
} |
res = true; |
res = 0; |
} |
PIUNLOCKHANDLE(h); |
845,14 → 841,14 |
return true; |
} |
Boolean readfile_guf(StandardFileReply* sfr, TCHAR** reason) { |
FFLoadingResult readfile_guf(StandardFileReply* sfr) { |
Handle h; |
Boolean res = false; |
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
FILEREF refnum; |
// TODO: Decode UTF-8 to ANSI (or "?" for unknown characters) |
if (!fileHasExtension(sfr, TEXT(".guf"))) return false; |
if (!fileHasExtension(sfr, TEXT(".guf"))) return MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
if (FSpOpenDF(&sfr->sfFile, fsRdPerm, &refnum) == noErr) { |
if ((h = readfileintohandle(refnum))) { |
865,8 → 861,7 |
PIUNLOCKHANDLE(h); |
PIDISPOSEHANDLE(h); |
FSClose(refnum); |
if (reason) *reason = FF_GetMsg_Cpy(MSG_INCOMPATIBLE_GUF_FILE_ID); |
return false; |
return MSG_INCOMPATIBLE_GUF_FILE_ID; |
} |
} |
else { |
873,8 → 868,7 |
PIUNLOCKHANDLE(h); |
PIDISPOSEHANDLE(h); |
FSClose(refnum); |
if (reason) *reason = FF_GetMsg_Cpy(MSG_INCOMPATIBLE_GUF_FILE_ID); |
return false; |
return MSG_INCOMPATIBLE_GUF_FILE_ID; |
} |
if (_gufReadProperty(q, count, "Info", "Title", out, sizeof(out))) { |
int i; |
933,7 → 927,7 |
} |
} |
res = true; |
res = 0; |
} |
PIUNLOCKHANDLE(h); |
945,14 → 939,14 |
return res; |
} |
Boolean readfile_afs_pff(StandardFileReply *sfr, TCHAR**reason){ |
FFLoadingResult readfile_afs_pff(StandardFileReply *sfr){ |
FILEREF r; |
Handle h; |
Boolean res = false; |
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
if(FSpOpenDF(&sfr->sfFile,fsRdPerm,&r) == noErr){ |
if( (h = readfileintohandle(r)) ){ |
if( (res = readparams_afs_pff(h,reason)) ) { |
if( 0 == (res = readparams_afs_pff(h)) ) { |
if (fileHasExtension(sfr, TEXT(".pff"))) { |
// If it is a Premiere settings file, we need to swap the channels red and blue |
// We just swap the pointers! |
968,21 → 962,21 |
FSClose(r); |
} |
else |
if (reason) *reason = FF_GetMsg_Cpy(MSG_CANNOT_OPEN_FILE_ID); |
res = MSG_CANNOT_OPEN_FILE_ID; |
return res; |
} |
Boolean readfile_ffl(StandardFileReply* sfr, TCHAR** reason) { |
FFLoadingResult readfile_ffl(StandardFileReply* sfr) { |
FILEREF rTmp, refnum; |
Handle h, hTmp; |
Boolean res = false; |
FFLoadingResult res = MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
StandardFileReply sfrTmp; |
OSErr e; |
char* p, * start; |
size_t est; |
if (!fileHasExtension(sfr, TEXT(".ffl"))) return false; |
if (!fileHasExtension(sfr, TEXT(".ffl"))) return MSG_LOADFILE_UNKNOWN_FORMAT_ID; |
if (FSpOpenDF(&sfr->sfFile, fsRdPerm, &refnum) == noErr) { |
if ((h = readfileintohandle(refnum))) { |
999,8 → 993,7 |
PIUNLOCKHANDLE(h); |
PIDISPOSEHANDLE(h); |
FSClose(refnum); |
if (reason) *reason = TEXT("Out of memory"); // TODO: translate |
return false; |
return MSG_OUT_OF_MEMORY_ID; |
} |
memcpy(q2, q, count); |
q2[count] = '\0'; |
1018,8 → 1011,7 |
PIUNLOCKHANDLE(h); |
PIDISPOSEHANDLE(h); |
FSClose(refnum); |
if (reason) *reason = TEXT("Invalid file signature"); // TODO: translate |
return false; |
return MSG_INVALID_FILE_SIGNATURE_ID; |
} |
} |
else if (lineNumber == 1) { |
1168,7 → 1160,5 |
} |
// TODO: show a different message when no filters were processed for some reason... |
// TODO: It's very confusing because this shows up as error message... |
if (reason) *reason = FF_GetMsg_Cpy(MSG_FFL_CONVERTED_ID); |
return false; |
return MSG_FFL_CONVERTED_ID; |
} |
/trunk/ui.c |
---|
322,7 → 322,6 |
StandardFileReply sfr; |
NavReplyRecord reply; |
static OSType types[] = {TEXT_FILETYPE,PS_FILTER_FILETYPE}; |
TCHAR*reason = NULL; |
HINSTANCE hShellRes; |
InternalState bakState; |
411,20 → 410,28 |
free(title); |
if (loadDlgRet) { |
FFLoadingResult res; |
// Backup everything, otherwise we might lose parameter data if the loading fails |
bakState = saveInternalState(); |
if (loadfile(&sfr, &reason)) { |
if (0 == (res = loadfile(&sfr))) { |
updatedialog(dp); |
maindlgupdate(dp); |
} |
else { |
alertuser_id(MSG_CANNOT_LOAD_SETTINGS_ID, reason); |
// Restore |
restoreInternalState(bakState); |
if (res == MSG_FFL_CONVERTED_ID) { |
showmessage_id(res); |
} |
else { |
TCHAR* reason = FF_GetMsg_Cpy(res); |
alertuser_id(MSG_CANNOT_LOAD_SETTINGS_ID, reason); |
FF_GetMsg_Free(reason); |
} |
} |
if (reason) FF_GetMsg_Free(reason); |
} |
break; |
} |