/* Derived from source code of TrueCrypt 7.1a, which is Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed by the TrueCrypt License 3.0. Modifications and additions to the original source code (contained in this file) and all other portions of this file are Copyright (c) 2013-2016 IDRIX and are governed by the Apache License 2.0 the full text of which is contained in the file License.txt included in VeraCrypt binary and source code distribution packages. */ #include "Language.h" #include "Dlgcode.h" #include "Dictionary.h" #include "Tcdefs.h" #include "Xml.h" #include "../Common/Resource.h" #ifdef TCMOUNT #include "../Mount/Resource.h" #endif #ifdef VOLFORMAT #include "../Format/Resource.h" #endif #ifdef SETUP #include "../Setup/Resource.h" #endif #include BOOL LocalizationActive; int LocalizationSerialNo; wchar_t UnknownString[1024] = {0}; static char *LanguageFileBuffer = NULL; static HANDLE LanguageFileFindHandle = INVALID_HANDLE_VALUE; static char PreferredLangId[6] = {0}; static char *LanguageResource = NULL; static DWORD LanguageResourceSize = 0; static char *HeaderResource[2] = {NULL, NULL}; static DWORD HeaderResourceSize[2] = {0, 0}; static char ActiveLangPackVersion[6] = {0}; static char *MapFirstLanguageFile () { if (LanguageFileFindHandle != INVALID_HANDLE_VALUE) { FindClose (LanguageFileFindHandle); LanguageFileFindHandle = INVALID_HANDLE_VALUE; } if (LanguageFileBuffer != NULL) { free (LanguageFileBuffer); LanguageFileBuffer = NULL; } if (LanguageResource == NULL) { DWORD size; LanguageResource = MapResource (L"Xml", IDR_LANGUAGE, &size); if (LanguageResource) LanguageResourceSize = size; } if (LanguageResource) { LanguageFileBuffer = malloc(LanguageResourceSize + 1); if (LanguageFileBuffer) { memcpy (LanguageFileBuffer, LanguageResource, LanguageResourceSize); LanguageFileBuffer[LanguageResourceSize] = 0; } } return LanguageFileBuffer; } static char *MapNextLanguageFile () { wchar_t f[TC_MAX_PATH*2], *t; WIN32_FIND_DATAW find; HANDLE file; DWORD read; BOOL bStatus; /* free memory here to avoid leaks */ if (LanguageFileBuffer != NULL) { free (LanguageFileBuffer); LanguageFileBuffer = NULL; } if (LanguageFileFindHandle == INVALID_HANDLE_VALUE) { GetModuleFileNameW (NULL, f, sizeof (f) / sizeof (f[0])); t = wcsrchr (f, L'\\'); if (t == NULL) return NULL; *t = 0; StringCbCatW (f, sizeof(f), L"\\Language*.xml"); LanguageFileFindHandle = FindFirstFileW (f, &find); } else if (!FindNextFileW (LanguageFileFindHandle, &find)) { FindClose (LanguageFileFindHandle); LanguageFileFindHandle = INVALID_HANDLE_VALUE; return NULL; } if (LanguageFileFindHandle == INVALID_HANDLE_VALUE) return NULL; if (find.nFileSizeHigh != 0) return NULL; LanguageFileBuffer = malloc(find.nFileSizeLow + 1); if (LanguageFileBuffer == NULL) return NULL; GetModuleFileNameW (NULL, f, sizeof (f) / sizeof(f[0])); t = wcsrchr (f, L'\\'); if (t == NULL) { free(LanguageFileBuffer); LanguageFileBuffer = NULL; return NULL; } t[1] = 0; StringCbCatW (f, sizeof(f),find.cFileName); file = CreateFileW (f, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL); if (file == INVALID_HANDLE_VALUE) { free(LanguageFileBuffer); LanguageFileBuffer = NULL; return NULL; } bStatus = ReadFile (file, LanguageFileBuffer, find.nFileSizeLow, &read, NULL); CloseHandle (file); if (!bStatus || (read != find.nFileSizeLow)) { free(LanguageFileBuffer); LanguageFileBuffer = NULL; return NULL; } LanguageFileBuffer [find.nFileSizeLow] = 0; // we have allocated (find.nFileSizeLow + 1) bytes return LanguageFileBuffer; } BOOL LoadLanguageFile () { DWORD size; BYTE *res; char *xml, *header, *headerPtr; char langId[6] = "en", attr[32768], key[128]; BOOL defaultLangParsed = FALSE, langFound = FALSE; WCHAR wattr[32768]; int i, intKey, len; char *xmlElements[] = {"control", "string", 0}; #ifdef TCMOUNT int headers[] = { IDR_COMMON_RSRC_HEADER, IDR_MOUNT_RSRC_HEADER, 0 }; #endif #ifdef VOLFORMAT int headers[] = { IDR_COMMON_RSRC_HEADER, IDR_FORMAT_RSRC_HEADER, 0 }; #endif #ifdef SETUP int headers[] = { IDR_COMMON_RSRC_HEADER, IDR_SETUP_RSRC_HEADER, 0 }; #endif LocalizationActive = FALSE; ActiveLangPackVersion[0] = 0; ClearDictionaryPool (); if (PreferredLangId[0] != 0) StringCbCopyA (langId, sizeof(langId), PreferredLangId); // Parse all available language files until preferred language is found for (res = MapFirstLanguageFile (); res != NULL; res = MapNextLanguageFile ()) { xml = (char *) res; xml = XmlFindElement (xml, "localization"); if (!xml) continue; // Required TrueCrypt version XmlGetAttributeText (xml, "prog-version", attr, sizeof (attr)); // Check version of external language file if (defaultLangParsed && strcmp (attr, VERSION_STRING) && strcmp (attr, "DEBUG")) { wchar_t m[2048]; StringCbPrintfW (m, sizeof(m), L"The installed lang
/*
 Derived from source code of TrueCrypt 7.1a, which is
 Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
 by the TrueCrypt License 3.0.

 Modifications and additions to the original source code (contained in this file) 
 and all other portions of this file are Copyright (c) 2013-2016 IDRIX
 and are governed by the Apache License 2.0 the full text of which is
 contained in the file License.txt included in VeraCrypt binary and source
 code distribution packages.
*/

#ifndef TC_HEADER_Main_Forms_WizardPage
#define TC_HEADER_Main_Forms_WizardPage

#include "Main/Main.h"

namespace VeraCrypt
{
	class WizardPage : public wxPanel
	{
	public:
		WizardPage (wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style)
			: wxPanel (parent, id, pos, size, style)
		{ }
		virtual ~WizardPage () { }

		wxString GetPageTitle () const { return PageTitle; }
		virtual bool IsValid () = 0;
		virtual void OnPageChanging (bool forward) { }
		wxString GetNextButtonText () const { return NextButtonText; }
		void SetNextButtonText (const wxString &text) { NextButtonText = text; }
		virtual void SetMaxStaticTextWidth (int width) { }
		void SetPageTitle (const wxString &title) { PageTitle = title; }
		virtual void SetPageText (const wxString &text) = 0;

		Event PageUpdatedEvent;

	protected:
		wxString PageTitle;
		wxString NextButtonText;
	};
}

#endif // TC_HEADER_Main_Forms_WizardPage