// ---------------------------------------------------------------------
BOOL WinCoveredCalcApp::initInstance()
{
	bool langFileLoaded = false;

	if (!base::initInstance())
	{
		return FALSE;
	}

	// コモンコントロール初期化
	::InitCommonControls();

	// レイヤードウィンドウ関連の API
	apiLayeredWindow.Initialize();
	
	// ウェイトカーソルを取得しておく
	waitCursor = ::LoadCursor(NULL, IDC_WAIT);

	// モニタ情報を取得しておく
	monitorInfo.Update();

	// ベースクラス初期化
	if (!init())
	{
		return FALSE;
	}

	// コマンドラインパラメータ解析
	CommandLineParam* clParam = GetCommandLineParam();
	clParam->SetParameter(__argc, __targv);

	// 言語ファイルの読み込み
	if (clParam->IsLangFileSpecified())
	{
		try
		{
			loadLangFile(clParam->GetLangFile());
			langFileLoaded = true;
		}
		catch (Exception* ex)
		{
			ex->Delete();

			// コマンドラインパラメータで指定された言語ファイルが読み込めなかったので無視します。
			DoMessageBox(NSID_EMSG_LOAD_COMMANDLINE_LANGFILE, MessageBoxProvider::ButtonType_OK, MessageBoxProvider::AlertType_Warning);
		}
	}

	// ウィンドウクラスの登録
	WinMainWindow::RegisterClass();

	//設定ファイルを準備
	Path settingFile;
	if (clParam->IsSettingFileSpecified())
	{
		// コマンドラインで設定ファイルが指定されていればそれを使う
		settingFile.Assign(clParam->GetSettingFile());
	}
	else
	{
		// デフォルト設定ファイルを使う
		try
		{
			readyDefaultSettingFilePath(settingFile);
		}
		catch (Exception* ex)
		{
			ExceptionMessageUtils::DoExceptionMessageBoxWithText(this, ex, NSID_EMSG_READY_DEFAULT_SETTING_FILE,
											MessageBoxProvider::ButtonType_OK, MessageBoxProvider::AlertType_Stop);
			ex->Delete();
			return FALSE;
		}
	}
	
	// 設定の読み込み
	try
	{
		loadSettings(settingFile);
	}
	catch (Exception* ex)
	{
		ex->Delete();
		return FALSE;
	}

	// 設定に保存された言語ファイルを読み込む
	if (!langFileLoaded)
	{
		AppSettings* appSettings = GetAppSettings();
		const Path settingPath = appSettings->GetLanguageFilePath();
		if (!settingPath.IsEmpty()) {
			Path langFileFullPath = MakeAbsoluteLangFilePath(settingPath);
			if (!langFileFullPath.IsEmpty())
			{
				try
				{
					loadLangFile(langFileFullPath);
					langFileLoaded = true;
				}
				catch (Exception* ex)
				{
					ex->Delete();

					// 設定ファイルに書かれた言語ファイルが読めません。
					DoMessageBox(NSID_EMSG_LOAD_SETTING_LANGFILE, MessageBoxProvider::ButtonType_OK, MessageBoxProvider::AlertType_Warning);
				}
			}
		}
	}
	
	if (!langFileLoaded)
	{
		// 設定に保存されていなければ、ユーザーに問い合わせる
		WinSelectLanguageDlg selectLangDlg;
		try
		{
			selectLangDlg.SetRelativeLangFilePath(Path(ALITERAL("enUS.cclxw")));
			int dlgResult = selectLangDlg.DoModal(NULL);
			if (IDOK != dlgResult)
			{
				return FALSE;
			}
		}
		catch (Exception* ex)
		{
			ExceptionMessageUtils::DoExceptionMessageBox(this, ex);
			ex->Delete();
			return FALSE;
		}

		Path langFilePath = selectLangDlg.GetRelativeLangFilePath();
		Path langFileFullPath = MakeAbsoluteLangFilePath(langFilePath);
		if (!langFileFullPath.IsEmpty())
		{
			try
			{
				loadLangFile(langFileFullPath);
				langFileLoaded = true;
				GetAppSettings()->SetLanguageFilePath(langFilePath);

			}
			catch (Exception* ex)
			{
				ex->Delete();

				// 言語ファイルが読めません。
				DoMessageBox(NSID_EMSG_LOAD_LANGFILE, MessageBoxProvider::ButtonType_OK, MessageBoxProvider::AlertType_Warning);
			}
		}
	}

	// キー定義名 DB のロード
	loadKeyNameDB();
	
	// キーマッピング読み込み
	loadKeyMappingsOnInit();
	
	// カバー読み込み
	try
	{
		AppSettings* appSettings = GetAppSettings();
		loadCoverDef(appSettings->GetBaseFolder(), appSettings->GetLastCoverDef(), appSettings->GetLastCoverNo());
	}
	catch (Exception* ex)
	{
		ExceptionMessageUtils::DoExceptionMessageBox(this, ex);
		ex->Delete();

		// デフォルトカバーで復活を試みる
		if (!restoreByDefaultCoverDef())
		{
			// ダメでした…。
			return FALSE;
		}
	}

	// メインウィンドウ生成
	DWORD exStyle = 0;
	if (GetAppSettings()->IsMainWindowAlwaysOnTop())
	{
		exStyle = WS_EX_TOPMOST;
	}
	const Point32& lastMainWindowPos = GetAppSettings()->GetLastMainWindowPos();
	if (!mainWindow.CreateEx(exStyle, WinMainWindow::GetWindowClassName(), ALITERAL("CoveredCalc"), WS_SYSMENU | WS_POPUP | WS_MINIMIZEBOX, lastMainWindowPos.x, lastMainWindowPos.y, 0, 0, NULL, NULL))
	{
		// デフォルトカバーにして再チャレンジ
		bool restored = false;
		if (restoreByDefaultCoverDef())
		{
			if (mainWindow.CreateEx(exStyle, WinMainWindow::GetWindowClassName(), ALITERAL("CoveredCalc"), WS_SYSMENU | WS_POPUP | WS_MINIMIZEBOX, lastMainWindowPos.x, lastMainWindowPos.y, 0, 0, NULL, NULL))
			{
				restored = true;
			}
		}
		
		if (!restored)
		{
			DoMessageBox(NSID_EMSG_CREATE_MAIN_WINDOW, MessageBoxProvider::ButtonType_OK, MessageBoxProvider::AlertType_Stop);
			return FALSE;
		}
	}
	::ShowWindow(mainWindow.m_hWnd, SW_SHOW);

	// カバーブラウザ生成
	Path baseFolderPath = GetAppSettings()->GetBaseFolder();
	if (baseFolderPath.IsEmpty())
	{
		baseFolderPath = getAppFolderPath();
	}
	coverBrowser.SetCoversFolderPath(baseFolderPath.Append(ALITERAL("Covers")));
	if (!coverBrowser.Create(NULL))
	{
		DoMessageBox(NSID_EMSG_CREATE_COVER_BROWSER, MessageBoxProvider::ButtonType_OK, MessageBoxProvider::AlertType_Stop);
	}

	::ShowWindow(mainWindow.m_hWnd, SW_SHOW);
	if (GetAppSettings()->IsCoverBrowserVisible())
	{
		::ShowWindow(coverBrowser.m_hWnd, SW_SHOW);
	}

	::SetForegroundWindow(mainWindow.m_hWnd);

	return TRUE;
}
Beispiel #2
0
void xmldata::loadLang(IrrlichtDevice * device)
{
	// --> Loader code
	// read configuration from xml file
	this->device=device;
		const u32 starttime = device->getTimer()->getRealTime();
        io::IXMLReaderUTF8* xml = device->getFileSystem()->createXMLReaderUTF8("../media/lang.xml");

		Lang CurrentLang;

		core::stringc  MessageText = "";
		core::stringc  language = "";
		core::stringc  description = "";
		core::stringc  filename = "";
		core::stringw  result = L"";

		bool inside = false;
		bool found = false;

		// Language counter (using the XML hierachy)
		u32 count = 0;
		u32 linecount = 0;
		u32 linecount2 = 0;

        while(xml && xml->read())
        {
                switch(xml->getNodeType())
                {
                case io::EXN_TEXT:		
                        break;

                case io::EXN_ELEMENT:
                {
					
						if (core::stringw("language") == xml->getNodeName())
						{
							linecount=0;
							linecount2=0;
							if (!inside) 
							{
								inside=true;							
							}

                            language = stringc(xml->getAttributeValue("name"));
							description = stringc(xml->getAttributeValue("description"));								
							if (LANGManager::getInstance()->defaultLanguage==language)
							{
								found=true; //Get the filename of the xml file for the lang if it's the current one and if it's exist
								filename = stringc(xml->getAttributeValue("filename"));
							}
						}

						if ((core::stringw("text") == xml->getNodeName()) && filename=="" && (language==LANGManager::getInstance()->defaultLanguage))
						{

								wchar_t out[255];

								utf8ToWchar(xml->getAttributeValue("id"), out, 255);
								CurrentLang.name = stringw(out);
								
								utf8ToWchar(xml->getAttributeValue("str"), out, 255);
								CurrentLang.text=stringw(out);

								LANGManager::getInstance()->language.push_back(CurrentLang);
								linecount++;
						}
						if (core::stringw("about") == xml->getNodeName() && filename=="" && (language==LANGManager::getInstance()->defaultLanguage))
						{
								wchar_t out[255];
								CurrentLang.name=L"txt_about";
								utf8ToWchar(xml->getAttributeValue("str"), out, 255);
								CurrentLang.text=stringw(out);
								LANGManager::getInstance()->aboutext.push_back(CurrentLang);
						}
				}
                break;

				case io::EXN_ELEMENT_END:
					if (!inside)
					{
						linecount=0;
						linecount2=0;
					}

					if (inside)
						count++;

					inside = false;
					break;
                default:
                        break;
                }
        }

		/*
		core::stringw countstr = ((core::stringw)L"Language count: ")+(core::stringw)(count);
		stats->addItem(countstr.c_str());

		const u32 endtime = device->getTimer()->getRealTime();
		u32 time = endtime-starttime;

		stats->addItem(((core::stringw)L"Parse time used: "+(core::stringw)time+L" ms.").c_str()); */

        if (xml)
                xml->drop(); // don't forget to delete the xml reader

		if (filename!="") // If the langage string is not stored in lang, get it from the associated filename.
			loadLangFile(filename);
	// <-- Loader code

}