no message
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@634 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
18d56c60ce
commit
c97a1b79c9
3 changed files with 83 additions and 54 deletions
64
Source/nlf.cpp
Normal file
64
Source/nlf.cpp
Normal file
|
@ -0,0 +1,64 @@
|
|||
#include <Windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "nlf.h"
|
||||
|
||||
char SkipComments(FILE *f) {
|
||||
char c;
|
||||
while (c = fgetc(f))
|
||||
if (c == '#' || c == ';') {
|
||||
while (c = fgetc(f))
|
||||
if (c == '\n') break;
|
||||
}
|
||||
else break;
|
||||
return c;
|
||||
}
|
||||
|
||||
// NSIS Language File parser
|
||||
NLF::NLF(char *filename) {
|
||||
FILE *f = fopen(filename, "r");
|
||||
if (!f) throw runtime_error("Can't open language file!");
|
||||
|
||||
char buf[1024];
|
||||
buf[0] = SkipComments(f);
|
||||
fgets(buf+1, 1024, f);
|
||||
|
||||
// Check header
|
||||
if (strncmp(buf, "NLF v", 5)) throw runtime_error("Invalid language file!");
|
||||
if (atoi(buf+5) != NLF_VERSION) throw runtime_error("Language file version doesn't match NSIS version!");
|
||||
|
||||
// Get language ID
|
||||
buf[0] = SkipComments(f);
|
||||
fgets(buf+1, 1024, f);
|
||||
m_wLangId = atoi(buf);
|
||||
|
||||
// Read strings
|
||||
for (int i = 0; i < NLF_STRINGS; i++) {
|
||||
buf[0] = SkipComments(f);
|
||||
fgets(buf+1, 1024, f);
|
||||
if (lstrlen(buf) == 1023) {
|
||||
wsprintf(buf, "String too long (string #%d)!", i);
|
||||
throw runtime_error(buf);
|
||||
}
|
||||
m_szStrings[i] = new char[lstrlen(buf)+1];
|
||||
lstrcpy(m_szStrings[i], buf);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
NLF::~NLF() {
|
||||
MessageBox(0, "destructor", "info", MB_OK);
|
||||
for (int i = 0; i < NLF_STRINGS; i++) {
|
||||
delete [] m_szStrings[i];
|
||||
}
|
||||
}
|
||||
|
||||
WORD NLF::GetLang() {
|
||||
return m_wLangId;
|
||||
}
|
||||
|
||||
char* NLF::GetString(int idx) {
|
||||
if (idx < 0 || idx >= NLF_STRINGS) return 0;
|
||||
return m_szStrings[idx];
|
||||
}
|
59
Source/nlf.h
59
Source/nlf.h
|
@ -1,7 +1,8 @@
|
|||
#ifndef ___NLF___H_____
|
||||
#define ___NLF___H_____
|
||||
|
||||
#include <Windows.h>
|
||||
#include <StdExcept>
|
||||
using namespace std;
|
||||
|
||||
#define NLF_VERSION 1
|
||||
#define NLF_STRINGS 57
|
||||
|
@ -64,62 +65,14 @@
|
|||
#define NLF_RENAME 55
|
||||
#define NLF_SKIPPED 56
|
||||
|
||||
char SkipComments(FILE *f) {
|
||||
char c;
|
||||
while (c = fgetc(f))
|
||||
if (c == '#' || c == ';') {
|
||||
while (c = fgetc(f))
|
||||
if (c == '\n') break;
|
||||
}
|
||||
else break;
|
||||
return c;
|
||||
}
|
||||
|
||||
extern FILE *g_output;
|
||||
#define s(x) fprintf(g_output, x"\n"); fflush(g_output);
|
||||
#define s2(x,y) fprintf(g_output, x"\n", y); fflush(g_output);
|
||||
|
||||
// NSIS Language File parser
|
||||
class NLF {
|
||||
public:
|
||||
NLF(char *filename) {
|
||||
FILE *f = fopen(filename, "r");
|
||||
if (!f) throw runtime_error("Can't open language file!");
|
||||
NLF(char *filename);
|
||||
~NLF();
|
||||
|
||||
char buf[1024];
|
||||
buf[0] = SkipComments(f);
|
||||
fgets(buf+1, 1024, f);
|
||||
|
||||
// Check header
|
||||
if (strncmp(buf, "NLF v", 5)) throw runtime_error("Invalid language file!");
|
||||
if (atoi(buf+5) != NLF_VERSION) throw runtime_error("Language file version doesn't match NSIS version!");
|
||||
|
||||
// Get language ID
|
||||
buf[0] = SkipComments(f);
|
||||
fgets(buf+1, 1024, f);
|
||||
m_wLangId = atoi(buf);
|
||||
|
||||
// Read entries
|
||||
int i = 0;
|
||||
while (i < NLF_STRINGS) {
|
||||
buf[0] = SkipComments(f);
|
||||
fgets(buf+1, 1024, f);
|
||||
if (lstrlen(buf) == 1023) {
|
||||
wsprintf(buf, "String too long (string #%d)!", i);
|
||||
throw runtime_error(buf);
|
||||
}
|
||||
//m_szStrings[i] = new char[lstrlen(buf)];
|
||||
m_szStrings[i] = (char*)GlobalAlloc(GPTR, lstrlen(buf));
|
||||
lstrcpy(m_szStrings[i], buf);
|
||||
i++;
|
||||
}
|
||||
|
||||
for (i = 0; i < NLF_STRINGS; i++) {
|
||||
GlobalFree(m_szStrings[i]);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
WORD GetLang();
|
||||
char* GetString(int idx);
|
||||
|
||||
private:
|
||||
WORD m_wLangId;
|
||||
|
|
|
@ -1215,7 +1215,19 @@ int CEXEBuild::doCommand(int which_token, LineParser &line, FILE *fp, const char
|
|||
case TOK_LOADNLF:
|
||||
{
|
||||
SCRIPT_MSG("LoadLanguageFile: %s\n", line.gettoken_str(1));
|
||||
NLF *lang = new NLF(line.gettoken_str(1));
|
||||
try {
|
||||
NLF *newLang = new NLF(line.gettoken_str(1));
|
||||
for (int i = 0; i < build_langs.size(); i++)
|
||||
if (build_langs[i]->GetLang() == newLang->GetLang()) {
|
||||
ERROR_MSG("Error: Can't add same language twice!\n");
|
||||
return PS_ERROR;
|
||||
}
|
||||
build_langs.push_back(newLang);
|
||||
}
|
||||
catch (exception &err) {
|
||||
ERROR_MSG("Error while adding language file: %s", err.what());
|
||||
return PS_ERROR;
|
||||
}
|
||||
}
|
||||
return make_sure_not_in_secorfunc(line.gettoken_str(0));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue