ifstream does not have a wchar_t constructor, use FILE* and our FOPEN wrapper.
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6215 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
2c89cca183
commit
615ce82030
1 changed files with 15 additions and 27 deletions
|
@ -63,38 +63,25 @@ struct NSISException : public std::runtime_error
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
size_t file_size(ifstream& file) {
|
|
||||||
const ifstream::pos_type pos = file.tellg();
|
|
||||||
|
|
||||||
file.seekg(0, ios::end);
|
|
||||||
|
|
||||||
ifstream::pos_type result = file.tellg();
|
|
||||||
assert(result >= (ifstream::pos_type)0);
|
|
||||||
|
|
||||||
file.seekg(pos);
|
|
||||||
|
|
||||||
return (size_t)result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This function slurps the whole file into the vector.
|
// This function slurps the whole file into the vector.
|
||||||
// Modified so the huge vector isn't returned by value.
|
// Modified so the huge vector isn't returned by value.
|
||||||
void read_file(const tstring& filename, vector<unsigned char>& data) {
|
void read_file(const tstring& filename, vector<unsigned char>& data) {
|
||||||
ifstream file(filename.c_str(), ios::binary);
|
FILE*file = FOPEN(filename.c_str(), _T("rb"));
|
||||||
|
|
||||||
if (!file) {
|
if (!file) throw NSISException(_T("Can't open file '") + filename + _T("'"));
|
||||||
throw NSISException(_T("Can't open file '") + filename + _T("'"));
|
|
||||||
}
|
MANAGE_WITH(file, fclose);
|
||||||
|
bool succ = false;
|
||||||
// get the file size
|
|
||||||
size_t filesize = file_size(file);
|
if (!fseek(file, 0, SEEK_END))
|
||||||
|
{
|
||||||
data.resize(filesize);
|
const long filesize = ftell(file);
|
||||||
|
rewind(file);
|
||||||
file.read(reinterpret_cast<char*>(&data[0]), filesize);
|
data.resize(filesize);
|
||||||
|
size_t cbio = fread(reinterpret_cast<char*>(&data[0]), 1, filesize, file);
|
||||||
if (size_t(file.tellg()) != filesize) { // ifstream::eof doesn't return true here
|
succ = cbio == filesize;
|
||||||
throw NSISException(_T("Couldn't read entire file '") + filename + _T("'"));
|
|
||||||
}
|
}
|
||||||
|
if (!succ) throw NSISException(_T("Couldn't read entire file '") + filename + _T("'"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +91,7 @@ void Plugins::GetExports(const tstring &pathToDll, bool displayInfo)
|
||||||
PIMAGE_NT_HEADERS NTHeaders;
|
PIMAGE_NT_HEADERS NTHeaders;
|
||||||
try {
|
try {
|
||||||
read_file(pathToDll, dlldata);
|
read_file(pathToDll, dlldata);
|
||||||
|
if (dlldata.empty()) return;
|
||||||
NTHeaders = CResourceEditor::GetNTHeaders(&dlldata[0]);
|
NTHeaders = CResourceEditor::GetNTHeaders(&dlldata[0]);
|
||||||
} catch (std::runtime_error&) {
|
} catch (std::runtime_error&) {
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue