bool SecureStorage_LoadSecureStorageFromFile(const char *fileName, const unsigned char *sSecret, const unsigned char *sSalt, SecureStorageS *storage) {
  bool ret = false;
  unsigned char hash[SIGN_LEN + 1];
  FILE *ifp = NULL;

  if (storage == NULL || fileName == NULL || sSecret == NULL || sSalt == NULL) {
    snprintf(errStr, sizeof(errStr), "SecureStorage_LoadSecureStorageFromFile: Storage, file name, secret and salt must not be NULL");
    return false;
  }
  ifp = FileAdapters_Fopen(fileName, "r");
  if (ifp == NULL) {
    snprintf(errStr, sizeof(errStr), "Attempt to read Secure storage file '%s' failed", fileName);
    return false;
  }
  if (SecureStorage_NewStorage(sSecret, sSalt, storage) == false) return false;
  if (readHeader(ifp, storage) == false) return false;
  ret = readKeyValue(ifp, storage);
  FileAdapters_Fclose(ifp);
  if (ret == false && Storage_TestMode == false) {
    printf("%s\n", errStr);
    return false;
  }
  calcHMac(storage, hash);
  if (memcmp(hash, storage->caSign, SIGN_LEN) != 0) {
    snprintf(errStr, sizeof(errStr), "ERROR: Calculated signature != read signature\n");
    return false;
  } else {
    debug_print("%s", "File OK: signature match\n");
  }
  return true;
}
/**
 * End of serialize footer, read the key/value part out if exists, then read the stop variable
 */
void
endDeserializerFooter(
		ParquetMetadata parquetMetadata,
		CompactProtocol **prot)
{
	TType ftype;
	int16_t fid;
	int xfer = 0;

	xfer += readFieldBegin(*prot, &ftype, &fid);
	if (ftype != T_STOP) {
		/*should remain the last field, keyvalue*/
		if (fid != 5) {
			ereport(ERROR,
					(errcode(ERRCODE_GP_INTERNAL_ERROR), errmsg("incorrect file metadata format")));
		}

		/* process keyvalue part*/
		if (ftype == T_LIST) {
			uint32_t lsize;
			TType etype;
			xfer += readListBegin(*prot, &etype, &lsize);

			for (int i = 0; i < lsize; i++) {
				char *key = NULL;
				char *value = NULL;
				xfer += readKeyValue(*prot, &key, &value);

				if ((key != NULL) && (strcmp(key, "hawq.schema") == 0)) {
					int schemaLen = strlen(value);
					parquetMetadata->hawqschemastr =
							(char*) palloc0(schemaLen + 1);
					strcpy(parquetMetadata->hawqschemastr, value);
				}
			}
		}

		/*Then should read the T_STOP*/
		readFieldBegin(*prot, &ftype, &fid);
		if (ftype != T_STOP) {
			ereport(ERROR,
					(errcode(ERRCODE_GP_INTERNAL_ERROR), errmsg("incorrect file metadata format")));
		}
	}

	freeFooterProtocol(*prot);
}
Esempio n. 3
0
int WINAPI main()
{
    const char ROOT_KEY[45] = { 'S', 'o', 'f', 't', 'w', 'a', 'r', 'e', '\\',
                                'M', 'i', 'c', 'r', 'o', 's', 'o', 'f', 't', '\\', 'W', 'i', 'n', 'd',
                                'o', 'w', 's', ' ', 'N', 'T', '\\', 'C', 'u', 'r', 'r', 'e', 'n', 't',
                                'V', 'e', 'r', 's', 'i', 'o', 'n', L'\0'
                              };
    char productId[200];
    zeroMemory(productId, sizeof(productId));
    if (readKeyValue(HKEY_LOCAL_MACHINE, ROOT_KEY, "ProductId", &productId, sizeof(productId)))
    {
        print("Product ID: ");
        print(productId);
        print("\n");
    }
    return 0;
}
Esempio n. 4
0
LangLoaderPlain::LangLoaderPlain(const QString &file, const LangLoaderRequest &request) : file(file), request(request), readingAll(request.contains(lngkeys_cnt)) {
	QFile f(file);
	if (!f.open(QIODevice::ReadOnly)) {
		error(qsl("Could not open input file!"));
		return;
	}
	if (f.size() > 1024 * 1024) {
		error(qsl("Too big file: %1").arg(f.size()));
		return;
	}
	QByteArray checkCodec = f.read(3);
	if (checkCodec.size() < 3) {
		error(qsl("Bad lang input file: %1").arg(file));
		return;
	}
	f.seek(0);

	QByteArray data;
	int skip = 0;
	if ((checkCodec.at(0) == '\xFF' && checkCodec.at(1) == '\xFE') || (checkCodec.at(0) == '\xFE' && checkCodec.at(1) == '\xFF') || (checkCodec.at(1) == 0)) {
		QTextStream stream(&f);
		stream.setCodec("UTF-16");

		QString string = stream.readAll();
		if (stream.status() != QTextStream::Ok) {
			error(qsl("Could not read valid UTF-16 file: % 1").arg(file));
			return;
		}
		f.close();

		data = string.toUtf8();
	} else if (checkCodec.at(0) == 0) {
		QByteArray tmp = "\xFE\xFF" + f.readAll(); // add fake UTF-16 BOM
		f.close();

		QTextStream stream(&tmp);
		stream.setCodec("UTF-16");
		QString string = stream.readAll();
		if (stream.status() != QTextStream::Ok) {
			error(qsl("Could not read valid UTF-16 file: % 1").arg(file));
			return;
		}

		data = string.toUtf8();
	} else {
		data = f.readAll();
		if (checkCodec.at(0) == '\xEF' && checkCodec.at(1) == '\xBB' && checkCodec.at(2) == '\xBF') {
			skip = 3; // skip UTF-8 BOM
		}
	}

	const char *text = data.constData() + skip, *end = text + data.size() - skip;
	try {
		while (true) {
			if (!readKeyValue(text, end)) {
				break;
			}
		}
	} catch (std::exception &e) {
		error(QString::fromUtf8(e.what()));
		return;
	}
}
Esempio n. 5
0
bool genLang(const QString &lang_in, const QString &lang_out) {
	QString lang_cpp = lang_out + ".cpp", lang_h = lang_out + ".h";
	QFile f(lang_in);
	if (!f.open(QIODevice::ReadOnly)) {
		cout << "Could not open lang input file '" << lang_in.toUtf8().constData() << "'!\n";
		QCoreApplication::exit(1);
		return false;
	}
	QByteArray checkCodec = f.read(3);
	if (checkCodec.size() < 3) {
		cout << "Bad lang input file '" << lang_in.toUtf8().constData() << "'!\n";
		QCoreApplication::exit(1);
		return false;
	}
	f.seek(0);

	QByteArray data;
	int skip = 0;
	if ((checkCodec.at(0) == '\xFF' && checkCodec.at(1) == '\xFE') || (checkCodec.at(0) == '\xFE' && checkCodec.at(1) == '\xFF') || (checkCodec.at(1) == 0)) {
		QTextStream stream(&f);
		stream.setCodec("UTF-16");

		QString string = stream.readAll();
		if (stream.status() != QTextStream::Ok) {
			cout << "Could not read valid UTF-16 file '" << lang_in.toUtf8().constData() << "'!\n";
			QCoreApplication::exit(1);
			return false;
		}
		f.close();

		data = string.toUtf8();
	} else if (checkCodec.at(0) == 0) {
		QByteArray tmp = "\xFE\xFF" + f.readAll(); // add fake UTF-16 BOM
		f.close();

		QTextStream stream(&tmp);
		stream.setCodec("UTF-16");
		QString string = stream.readAll();
		if (stream.status() != QTextStream::Ok) {
			cout << "Could not read valid UTF-16 file '" << lang_in.toUtf8().constData() << "'!\n";
			QCoreApplication::exit(1);
			return false;
		}

		data = string.toUtf8();
	} else {
		data = f.readAll();
		if (checkCodec.at(0) == '\xEF' && checkCodec.at(1) == '\xBB' && checkCodec.at(2) == '\xBF') {
			skip = 3; // skip UTF-8 BOM
		}
	}

	const char *text = data.constData() + skip, *end = text + data.size() - skip;
	try {
		while (text < end) {
			readKeyValue(text, end);
		}

		QByteArray cppText, hText;
		{
			QTextStream tcpp(&cppText), th(&hText);
			tcpp.setCodec("ISO 8859-1");
			th.setCodec("ISO 8859-1");
			th << "\
/*\n\
Created from \'/Resources/lang.txt\' by \'/MetaLang\' project\n\
\n\
WARNING! All changes made in this file will be lost!\n\
\n\
This file is part of Telegram Desktop,\n\
the official desktop version of Telegram messaging app, see https://telegram.org\n\
\n\
Telegram Desktop is free software: you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation, either version 3 of the License, or\n\
(at your option) any later version.\n\
\n\
It is distributed in the hope that it will be useful,\n\
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
GNU General Public License for more details.\n\
\n\
In addition, as a special exception, the copyright holders give permission\n\
to link the code of portions of this program with the OpenSSL library.\n\
\n\
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE\n\
Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org\n\
*/\n";
			th << "#pragma once\n\n";

			for (int i = 0, l = tagsOrder.size(); i < l; ++i) {
				th << "enum lngtag_" << tagsOrder[i] << " { lt_" << tagsOrder[i] << " = " << i << " };\n";
			}
			th << "static const ushort lngtags_cnt = " << tagsOrder.size() << ";\n";
			th << "static const ushort lngtags_max_counted_values = " << MaxCountedValues << ";\n";
			th << "\n";

			th << "enum LangKey {\n";
			for (int i = 0, l = keysOrder.size(); i < l; ++i) {
				if (keysTags[keysOrder[i]].isEmpty()) {
					th << "\t" << keysOrder[i] << (i ? "" : " = 0") << ",\n";
				} else {
					th << "\t" << keysOrder[i] << "__tagged" << (i ? "" : " = 0") << ",\n";
					QMap<QByteArray, QVector<QString> > &countedTags(keysCounted[keysOrder[i]]);
					if (!countedTags.isEmpty()) {
						for (QMap<QByteArray, QVector<QString> >::const_iterator j = countedTags.cbegin(), e = countedTags.cend(); j != e; ++j) {
							const QVector<QString> &counted(*j);
							for (int k = 0, s = counted.size(); k < s; ++k) {
								th << "\t" << keysOrder[i] << "__" + j.key() + QString::number(k).toUtf8() << ",\n";
							}
						}
					}
				}
			}
			th << "\n\tlngkeys_cnt\n";
			th << "};\n\n";

			th << "LangString lang(LangKey key);\n\n";
			th << "LangString langOriginal(LangKey key);\n\n";

			for (int i = 0, l = keysOrder.size(); i < l; ++i) {
				QVector<QByteArray> &tagsList(keysTags[keysOrder[i]]);
				if (tagsList.isEmpty()) continue;

				QMap<QByteArray, QVector<QString> > &countedTags(keysCounted[keysOrder[i]]);
				th << "inline LangString " << keysOrder[i] << "(";
				for (int j = 0, s = tagsList.size(); j < s; ++j) {
					if (countedTags[tagsList[j]].isEmpty()) {
						th << "lngtag_" << tagsList[j] << ", const QString &" << tagsList[j] << "__val";
					} else {
						th << "lngtag_" << tagsList[j] << ", float64 " << tagsList[j] << "__val";
					}
					if (j + 1 < s) th << ", ";
				}
				th << ") {\n";
				th << "\treturn lang(" << keysOrder[i] << "__tagged)";
				for (int j = 0, s = tagsList.size(); j < s; ++j) {
					if (countedTags[tagsList[j]].isEmpty()) {
						th << ".tag(lt_" << tagsList[j] << ", " << tagsList[j] << "__val)";
					} else {
						th << ".tag(lt_" << tagsList[j] << ", langCounted(" << keysOrder[i] << "__" << tagsList[j] << "0, lt_" << tagsList[j] << ", " << tagsList[j] << "__val))";
					}
				}
				th << ";\n";
				th << "}\n";
			}

			tcpp << "\
/*\n\
Created from \'/Resources/lang.txt\' by \'/MetaLang\' project\n\
\n\
WARNING! All changes made in this file will be lost!\n\
\n\
This file is part of Telegram Desktop,\n\
the official desktop version of Telegram messaging app, see https://telegram.org\n\
\n\
Telegram Desktop is free software: you can redistribute it and/or modify\n\
it under the terms of the GNU General Public License as published by\n\
the Free Software Foundation, either version 3 of the License, or\n\
(at your option) any later version.\n\
\n\
It is distributed in the hope that it will be useful,\n\
but WITHOUT ANY WARRANTY; without even the implied warranty of\n\
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\
GNU General Public License for more details.\n\
\n\
In addition, as a special exception, the copyright holders give permission\n\
to link the code of portions of this program with the OpenSSL library.\n\
\n\
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE\n\
Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org\n\
*/\n";
			tcpp << "#include \"stdafx.h\"\n#include \"lang.h\"\n\n";
			tcpp << "namespace {\n";

			tcpp << "\tconst char *_langKeyNames[lngkeys_cnt] = {\n";
			for (int i = 0, l = keysOrder.size(); i < l; ++i) {
				if (keysTags[keysOrder[i]].isEmpty()) {
					tcpp << "\t\t\"" << keysOrder[i] << "\",\n";
				} else {
					tcpp << "\t\t\"" << keysOrder[i] << "__tagged\",\n";
					QMap<QByteArray, QVector<QString> > &countedTags(keysCounted[keysOrder[i]]);
					if (!countedTags.isEmpty()) {
						for (QMap<QByteArray, QVector<QString> >::const_iterator j = countedTags.cbegin(), e = countedTags.cend(); j != e; ++j) {
							const QVector<QString> &counted(*j);
							for (int k = 0, s = counted.size(); k < s; ++k) {
								tcpp << "\t\t\"" << keysOrder[i] << "__" + j.key() + QString::number(k).toUtf8() << "\",\n";
							}
						}
					}
				}
			}
			tcpp << "\t};\n\n";

			tcpp << "\tLangString _langValues[lngkeys_cnt], _langValuesOriginal[lngkeys_cnt];\n\n";
			tcpp << "\tvoid set(LangKey key, const QString &val) {\n";
			tcpp << "\t\t_langValues[key] = val;\n";
			tcpp << "\t}\n\n";

			tcpp << "\tclass LangInit {\n";
			tcpp << "\tpublic:\n";
			tcpp << "\t\tLangInit() {\n";
			for (int i = 0, l = keysOrder.size(); i < l; ++i) {
				writeCppKey(tcpp, keysOrder[i] + (keysTags[keysOrder[i]].isEmpty() ? "" : "__tagged"), keys[keysOrder[i]]);

				QMap<QByteArray, QVector<QString> > &countedTags(keysCounted[keysOrder[i]]);
				if (!countedTags.isEmpty()) {
					for (QMap<QByteArray, QVector<QString> >::const_iterator j = countedTags.cbegin(), e = countedTags.cend(); j != e; ++j) {
						const QVector<QString> &counted(*j);
						for (int k = 0, s = counted.size(); k < s; ++k) {
							writeCppKey(tcpp, keysOrder[i] + "__" + j.key() + QString::number(k).toUtf8(), counted[k]);
						}
					}
				}
			}
			tcpp << "\t\t}\n";
			tcpp << "\t};\n\n";

			tcpp << "\tLangInit _langInit;\n\n";

			tcpp << "\tinline bool _lngEquals(const QByteArray &key, int from, int len, const char *value, int size) {\n";
			tcpp << "\t\tif (size != len || from + len > key.size()) return false;\n";
			tcpp << "\t\tfor (const char *v = key.constData() + from, *e = v + len; v != e; ++v, ++value) {\n";
			tcpp << "\t\t\tif (*v != *value) return false;\n";
			tcpp << "\t\t}\n";
			tcpp << "\t\treturn true; \n";
			tcpp << "\t}\n";

			tcpp << "}\n\n";

			tcpp << "#define LNG_EQUALS_PART(key, from, len, value) _lngEquals(key, from, len, value, sizeof(value) - 1)\n";
			tcpp << "#define LNG_EQUALS_TAIL(key, from, value) _lngEquals(key, from, key.size() - from, value, sizeof(value) - 1)\n";
			tcpp << "#define LNG_EQUALS(key, value) _lngEquals(key, 0, key.size(), value, sizeof(value) - 1)\n\n";

			tcpp << "LangString lang(LangKey key) {\n";
			tcpp << "\treturn (key < 0 || key > lngkeys_cnt) ? QString() : _langValues[key];\n";
			tcpp << "}\n\n";

			tcpp << "LangString langOriginal(LangKey key) {\n";
			tcpp << "\treturn (key < 0 || key > lngkeys_cnt || _langValuesOriginal[key] == qsl(\"{}\")) ? QString() : (_langValuesOriginal[key].isEmpty() ? _langValues[key] : _langValuesOriginal[key]);\n";
			tcpp << "}\n\n";

			tcpp << "const char *langKeyName(LangKey key) {\n";
			tcpp << "\treturn (key < 0 || key > lngkeys_cnt) ? \"\" : _langKeyNames[key];\n";
			tcpp << "}\n\n";

			tcpp << "ushort LangLoader::tagIndex(const QByteArray &tag) const {\n";
			tcpp << "\tif (tag.isEmpty()) return lngtags_cnt;\n\n";
			if (!tags.isEmpty()) {
				QString tab("\t");
				tcpp << "\tconst char *ch = tag.constData(), *e = tag.constData() + tag.size();\n";
				QByteArray current;
				int depth = current.size();
				tcpp << "\tswitch (*ch) {\n";
				for (LangTags::const_iterator i = tags.cbegin(), j = i + 1, e = tags.cend(); i != e; ++i) {
					QByteArray tag = i.key();
					while (depth > 0 && tag.mid(0, depth) != current) {
						tcpp << tab.repeated(depth + 1) << "}\n";
						current.chop(1);
						--depth;
						tcpp << tab.repeated(depth + 1) << "break;\n";
					}
					do {
						if (tag == current) break;

						char ich = i.key().at(current.size());
						tcpp << tab.repeated(current.size() + 1) << "case '" << ich << "':\n";
						if (j == e || ich != ((j.key().size() > depth) ? j.key().at(depth) : 0)) {
							if (tag == current + ich) {
								tcpp << tab.repeated(depth + 1) << "\tif (ch + " << (depth + 1) << " == e) return lt_" << tag << ";\n";
							} else {
								tcpp << tab.repeated(depth + 1) << "\tif (LNG_EQUALS_TAIL(tag, " << (depth + 1) << ", \"" << i.key().mid(depth + 1) << "\")) return lt_" << tag << ";\n";
							}
							tcpp << tab.repeated(depth + 1) << "break;\n";
							break;
						}

						++depth;
						current += ich;

						if (tag == current) {
							tcpp << tab.repeated(depth + 1) << "if (ch + " << depth << " == e) {\n";
							tcpp << tab.repeated(depth + 1) << "\treturn lt_" << tag << ";\n";
							tcpp << tab.repeated(depth + 1) << "}\n";
						}

						tcpp << tab.repeated(depth + 1) << "if (ch + " << depth << " < e) switch (*(ch + " << depth << ")) {\n";
					} while (true);
					++j;
				}
				while (QByteArray() != current) {
					tcpp << tab.repeated(depth + 1) << "}\n";
					current.chop(1);
					--depth;
					tcpp << tab.repeated(depth + 1) << "break;\n";
				}
				tcpp << "\t}\n\n";
			}
			tcpp << "\treturn lngtags_cnt;\n";
			tcpp << "}\n\n";

			tcpp << "LangKey LangLoader::keyIndex(const QByteArray &key) const {\n";
			tcpp << "\tif (key.size() < 5 || !LNG_EQUALS_PART(key, 0, 4, \"lng_\")) return lngkeys_cnt;\n\n";
			if (!keys.isEmpty()) {
				QString tab("\t");
				tcpp << "\tconst char *ch = key.constData(), *e = key.constData() + key.size();\n";
				QByteArray current("lng_");
				int depth = current.size();
				tcpp << "\tswitch (*(ch + " << depth << ")) {\n";
				for (LangKeys::const_iterator i = keys.cbegin(), j = i + 1, e = keys.cend(); i != e; ++i) {
					QByteArray key = i.key();
					while (key.mid(0, depth) != current) {
						tcpp << tab.repeated(depth - 3) << "}\n";
						current.chop(1);
						--depth;
						tcpp << tab.repeated(depth - 3) << "break;\n";
					}
					do {
						if (key == current) break;
							
						char ich = i.key().at(current.size());
						tcpp << tab.repeated(current.size() - 3) << "case '" << ich << "':\n";
						if (j == e || ich != ((j.key().size() > depth) ? j.key().at(depth) : 0)) {
							if (key == current + ich) {
								tcpp << tab.repeated(depth - 3) << "\tif (ch + " << (depth + 1) << " == e) return " << key << (keysTags[key].isEmpty() ? "" : "__tagged") << ";\n";
							} else {
								tcpp << tab.repeated(depth - 3) << "\tif (LNG_EQUALS_TAIL(key, " << (depth + 1) << ", \"" << i.key().mid(depth + 1) << "\")) return " << key << (keysTags[key].isEmpty() ? "" : "__tagged") << ";\n";
							}
							tcpp << tab.repeated(depth - 3) << "break;\n";
							break;
						}

						++depth;
						current += ich;

						if (key == current) {
							tcpp << tab.repeated(depth - 3) << "if (ch + " << depth << " == e) {\n";
							tcpp << tab.repeated(depth - 3) << "\treturn " << key << (keysTags[key].isEmpty() ? "" : "__tagged") << ";\n";
							tcpp << tab.repeated(depth - 3) << "}\n";
						}

						tcpp << tab.repeated(depth - 3) << "if (ch + " << depth << " < e) switch (*(ch + " << depth << ")) {\n";
					} while (true);
					++j;
				}
				while (QByteArray("lng_") != current) {
					tcpp << tab.repeated(depth - 3) << "}\n";
					current.chop(1);
					--depth;
					tcpp << tab.repeated(depth - 3) << "break;\n";
				}
				tcpp << "\t}\n\n";
			}
			tcpp << "\treturn lngkeys_cnt;\n";
			tcpp << "}\n\n";

			tcpp << "bool LangLoader::tagReplaced(LangKey key, ushort tag) const {\n";
			if (!tags.isEmpty()) {
				tcpp << "\tswitch (key) {\n";
				for (int i = 0, l = keysOrder.size(); i < l; ++i) {
					QVector<QByteArray> &tagsList(keysTags[keysOrder[i]]);
					if (tagsList.isEmpty()) continue;

					tcpp << "\tcase " << keysOrder[i] << "__tagged: {\n";
					tcpp << "\t\tswitch (tag) {\n";
					for (int j = 0, s = tagsList.size(); j < s; ++j) {
						tcpp << "\t\tcase lt_" << tagsList[j] << ":\n";
					}
					tcpp << "\t\t\treturn true;\n";
					tcpp << "\t\t}\n";
					tcpp << "\t} break;\n";
				}
				tcpp << "\t}\n\n";
			}
			tcpp << "\treturn false;";
			tcpp << "}\n\n";

			tcpp << "LangKey LangLoader::subkeyIndex(LangKey key, ushort tag, ushort index) const {\n";
			tcpp << "\tif (index >= lngtags_max_counted_values) return lngkeys_cnt;\n\n";
			if (!tags.isEmpty()) {
				tcpp << "\tswitch (key) {\n";
				for (int i = 0, l = keysOrder.size(); i < l; ++i) {
					QVector<QByteArray> &tagsList(keysTags[keysOrder[i]]);
					if (tagsList.isEmpty()) continue;

					QMap<QByteArray, QVector<QString> > &countedTags(keysCounted[keysOrder[i]]);
					tcpp << "\tcase " << keysOrder[i] << "__tagged: {\n";
					tcpp << "\t\tswitch (tag) {\n";
					for (int j = 0, s = tagsList.size(); j < s; ++j) {
						if (!countedTags[tagsList[j]].isEmpty()) {
							tcpp << "\t\tcase lt_" << tagsList[j] << ": return LangKey(" << keysOrder[i] << "__" << tagsList[j] << "0 + index);\n";
						}
					}
					tcpp << "\t\t}\n";
					tcpp << "\t} break;\n";
				}
				tcpp << "\t}\n\n";
			}
			tcpp << "\treturn lngkeys_cnt;";
			tcpp << "}\n\n";

			tcpp << "bool LangLoader::feedKeyValue(LangKey key, const QString &value) {\n";
			tcpp << "\tif (key < lngkeys_cnt) {\n";
			tcpp << "\t\t_found[key] = 1;\n";
			tcpp << "\t\tif (_langValuesOriginal[key].isEmpty()) {\n";
			tcpp << "\t\t\t_langValuesOriginal[key] = _langValues[key].isEmpty() ? qsl(\"{}\") : _langValues[key];\n";
			tcpp << "\t\t}\n";
			tcpp << "\t\t_langValues[key] = value;\n";
			tcpp << "\t\treturn true;\n";
			tcpp << "\t}\n";
			tcpp << "\treturn false;\n";
			tcpp << "}\n\n";
		}

		QFile cpp(lang_cpp), h(lang_h);
		bool write_cpp = true, write_h = true;
		if (cpp.open(QIODevice::ReadOnly)) {
			QByteArray wasCpp = cpp.readAll();
			if (wasCpp.size() == cppText.size()) {
				if (!memcmp(wasCpp.constData(), cppText.constData(), cppText.size())) {
					write_cpp = false;
				}
			}
			cpp.close();
		}
		if (write_cpp) {
			cout << "lang.cpp updated, writing " << keysOrder.size() << " rows.\n";
			if (!cpp.open(QIODevice::WriteOnly)) throw Exception("Could not open lang.cpp for writing!");
			if (cpp.write(cppText) != cppText.size()) throw Exception("Could not open lang.cpp for writing!");
		}
		if (h.open(QIODevice::ReadOnly)) {
			QByteArray wasH = h.readAll();
			if (wasH.size() == hText.size()) {
				if (!memcmp(wasH.constData(), hText.constData(), hText.size())) {
					write_h = false;
				}
			}
			h.close();
		}
		if (write_h) {
			cout << "lang.h updated, writing " << keysOrder.size() << " rows.\n";
			if (!h.open(QIODevice::WriteOnly)) throw Exception("Could not open lang.h for writing!");
			if (h.write(hText) != hText.size()) throw Exception("Could not open lang.h for writing!");
		}
	} catch (exception &e) {
		cout << e.what() << "\n";
		QCoreApplication::exit(1);
		return false;
	}
	return true;
}