-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibutil.cpp
93 lines (89 loc) · 2.68 KB
/
libutil.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "libutil.hpp"
unsigned short int getLibType(HINSTANCE hLib) {
char testString[12];
if(hLib < 32) {
return LIB_UNKNOWN;
}
else {
if(LoadString(hLib,IDS_LIBTYPE,testString,12)) {
if(((std::string)testString)==STR_CODEPAGE) {
return LIB_CODEPAGE;
}
else if(((std::string)testString)==STR_STRINGTABLE) {
return LIB_STRINGTABLE;
}
else {
return LIB_UNKNOWN;
}
}
else {
return LIB_UNKNOWN;
}
}
}
std::string getCodePageInfo(HINSTANCE hLib) {
char testString[12];
if(hLib < 32) {
return "";
}
else {
if(LoadString(hLib,IDS_CPNAME,testString,12)) {
return (std::string)testString;
}
else {
return "";
}
}
}
bool listAvailableLibs(char* appPath, LIBRARIES &libraries) {
HINSTANCE hLib=NULL;
bool anyFound=false;
std::string searchString=getCurrentDirectory(appPath)+"*.DLL";
DIR *directory=opendir(searchString.c_str());
std::string temp="";
LIB_FILE_INFO fileInfo;
libraries.clear();
while(directory=readdir(directory)) {
hLib=LoadLibrary(directory->d_name);
switch(getLibType(hLib)) {
case LIB_CODEPAGE:
fileInfo.type=LIB_CODEPAGE;
fileInfo.filename=directory->d_name;
temp=getCodePageInfo(hLib);
if(temp!="") {
fileInfo.relatedInfo=temp;
libraries.push_back(fileInfo);
if(!anyFound) {
anyFound=true;
}
}
break;
case LIB_STRINGTABLE:
fileInfo.type=LIB_STRINGTABLE;
fileInfo.filename=directory->d_name;
// TODO: all the rest like above
break;
default:
break;
}
FreeLibrary(hLib);
}
return anyFound;
}
std::string findAnyCodePage(LIBRARIES &libraries) {
LIB_ITER it;
std::string selectedFile="";
std::string defaultCodePage=getCodePage();
for(it=libraries.begin(); it!=libraries.end(); ++it) {
if(it->type==LIB_CODEPAGE) {
if(selectedFile=="") {
selectedFile=it->filename;
}
if(it->relatedInfo==defaultCodePage) {
selectedFile=it->filename;
return selectedFile; // default system code page found - it is the best result
}
}
}
return selectedFile;
}