Subversion Repositories filter_foundry

Rev

Rev 522 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 522 Rev 536
1
/*
1
/*
2
    This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
2
    This file is part of "Filter Foundry", a filter plugin for Adobe Photoshop
3
    Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.com.au
3
    Copyright (C) 2003-2009 Toby Thain, toby@telegraphics.net
4
    Copyright (C) 2018-2022 Daniel Marschall, ViaThinkSoft
4
    Copyright (C) 2018-2022 Daniel Marschall, ViaThinkSoft
5
 
5
 
6
    This program is free software; you can redistribute it and/or modify
6
    This program is free software; you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation; either version 2 of the License, or
8
    the Free Software Foundation; either version 2 of the License, or
9
    (at your option) any later version.
9
    (at your option) any later version.
10
 
10
 
11
    This program is distributed in the hope that it will be useful,
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
14
    GNU General Public License for more details.
15
 
15
 
16
    You should have received a copy of the GNU General Public License
16
    You should have received a copy of the GNU General Public License
17
    along with this program; if not, write to the Free Software
17
    along with this program; if not, write to the Free Software
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
*/
19
*/
20
 
20
 
21
#include "ff.h"
21
#include "ff.h"
22
 
22
 
23
void strcpy_advance_id(TCHAR** str, int msgid) {
23
void strcpy_advance_id(TCHAR** str, int msgid) {
24
    int len = FF_GetMsg(*str, msgid);
24
    int len = FF_GetMsg(*str, msgid);
25
    *str += len;
25
    *str += len;
26
}
26
}
27
 
27
 
28
// Attention: No bounds checking!
28
// Attention: No bounds checking!
29
int FF_GetMsg(TCHAR* ret, int MsgId) {
29
int FF_GetMsg(TCHAR* ret, int MsgId) {
30
#ifdef WIN_ENV
30
#ifdef WIN_ENV
31
 
31
 
32
#ifdef UNICODE
32
#ifdef UNICODE
33
    TCHAR* szMsg;
33
    TCHAR* szMsg;
34
    int len;
34
    int len;
35
    len = LoadString(hDllInstance, MsgId, (LPTSTR)&szMsg, 0);
35
    len = LoadString(hDllInstance, MsgId, (LPTSTR)&szMsg, 0);
36
    if (len == 0) return 0; // resource not found
36
    if (len == 0) return 0; // resource not found
37
    if (ret != NULL) {
37
    if (ret != NULL) {
38
        LoadString(hDllInstance, MsgId, ret, len + 1);
38
        LoadString(hDllInstance, MsgId, ret, len + 1);
39
    }
39
    }
40
    return len;
40
    return len;
41
#else
41
#else
42
    // LoadStringA is either broken or badly documented!
42
    // LoadStringA is either broken or badly documented!
43
    // The documentation says that you receive a read-only string reference as well as the length as return value if cchBufferMax==0.
43
    // The documentation says that you receive a read-only string reference as well as the length as return value if cchBufferMax==0.
44
    // Reality shows that return value is -1 if cchBufferMax==0.
44
    // Reality shows that return value is -1 if cchBufferMax==0.
45
    // https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/8d8c5382-1867-460a-a18f-70dc425ffe2f/loadstring-not-behaving-as-documented?forum=windowssdk
45
    // https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/8d8c5382-1867-460a-a18f-70dc425ffe2f/loadstring-not-behaving-as-documented?forum=windowssdk
46
    // We cannot receive a read-only memory using LoadStringA, because the WinAPI needs to do a Unicode-to-ANSI convertion,
46
    // We cannot receive a read-only memory using LoadStringA, because the WinAPI needs to do a Unicode-to-ANSI convertion,
47
    // so we must define some max limit.
47
    // so we must define some max limit.
48
    TCHAR szMsg[4096];
48
    TCHAR szMsg[4096];
49
    int len;
49
    int len;
50
    len = LoadString(hDllInstance, MsgId, (LPTSTR)&szMsg, 4096);
50
    len = LoadString(hDllInstance, MsgId, (LPTSTR)&szMsg, 4096);
51
    if (len == 0) return 0; // resource not found
51
    if (len == 0) return 0; // resource not found
52
    if (ret != NULL) {
52
    if (ret != NULL) {
53
        LoadString(hDllInstance, MsgId, ret, len + 1);
53
        LoadString(hDllInstance, MsgId, ret, len + 1);
54
    }
54
    }
55
    return len;
55
    return len;
56
#endif
56
#endif
57
 
57
 
58
#else
58
#else
59
        Str255 msg;
59
        Str255 msg;
60
        GetIndString(msg, 1000, MsgId);
60
        GetIndString(msg, 1000, MsgId);
61
    myp2cstrcpy(ret, msg);
61
    myp2cstrcpy(ret, msg);
62
#endif
62
#endif
63
}
63
}
64
 
64
 
65
// Attention: Requires FF_GetMsg_Free(), otherwise memory is leaked
65
// Attention: Requires FF_GetMsg_Free(), otherwise memory is leaked
66
TCHAR* FF_GetMsg_Cpy(int MsgId) {
66
TCHAR* FF_GetMsg_Cpy(int MsgId) {
67
#ifdef WIN_ENV
67
#ifdef WIN_ENV
68
    int len;
68
    int len;
69
    TCHAR* ret;
69
    TCHAR* ret;
70
    len = FF_GetMsg(NULL, MsgId);
70
    len = FF_GetMsg(NULL, MsgId);
71
    if (len == 0) return NULL; // resource not found
71
    if (len == 0) return NULL; // resource not found
72
    ret = (TCHAR*)malloc((len+1) * sizeof(TCHAR));
72
    ret = (TCHAR*)malloc((len+1) * sizeof(TCHAR));
73
    if (ret == NULL) return NULL;
73
    if (ret == NULL) return NULL;
74
    LoadString(hDllInstance, MsgId, ret, len+1);
74
    LoadString(hDllInstance, MsgId, ret, len+1);
75
    return ret;
75
    return ret;
76
#else
76
#else
77
    Str255 msg;
77
    Str255 msg;
78
    TCHAR* ret;
78
    TCHAR* ret;
79
    ret = (TCHAR*)malloc((len + 1) * sizeof(TCHAR));
79
    ret = (TCHAR*)malloc((len + 1) * sizeof(TCHAR));
80
    GetIndString(msg, 1000, MsgId);
80
    GetIndString(msg, 1000, MsgId);
81
    myp2cstrcpy(ret, msg);
81
    myp2cstrcpy(ret, msg);
82
    return ret;
82
    return ret;
83
#endif
83
#endif
84
}
84
}
85
 
85
 
86
void FF_GetMsg_Free(TCHAR* str) {
86
void FF_GetMsg_Free(TCHAR* str) {
87
    free(str);
87
    free(str);
88
}
88
}
-
 
89