UINT __stdcall DialogInstall::InstallThread(void* pParam)
{
	DialogInstall* dialog = (DialogInstall*)pParam;

	if (!CloseRainmeterIfActive())
	{
		MessageBox(dialog->m_Window, L"Unable to close Rainmeter.", L"Rainmeter Skin Installer", MB_ERROR);
	}
	else
	{
		HWND progressText = GetDlgItem(dialog->m_TabInstall.GetWindow(), IDC_INSTALLTAB_INPROGRESS_TEXT);
		ShowWindow(progressText, SW_SHOWNORMAL);

		HWND progressBar = GetDlgItem(dialog->m_TabInstall.GetWindow(), IDC_INSTALLTAB_PROGRESS);
		ShowWindow(progressBar, SW_SHOWNORMAL);
		SendMessage(progressBar, PBM_SETMARQUEE, (WPARAM)TRUE, 0);

		if (!dialog->InstallPackage())
		{
			ShowWindow(progressText, SW_HIDE);
			ShowWindow(progressBar, SW_HIDE);

			if (dialog->m_ErrorMessage.empty())
			{
				dialog->m_ErrorMessage = L"Unknown error.";
			}
			dialog->m_ErrorMessage += L"\n\nClick OK to close Skin Installer.";

			MessageBox(dialog->m_Window, dialog->m_ErrorMessage.c_str(), L"Rainmeter Skin Installer", MB_ERROR);

			dialog->m_LoadSkins.clear();
			dialog->m_LoadLayout.clear();
		}

		dialog->LaunchRainmeter();
	}

	EndDialog(dialog->GetWindow(), 0);
	return 0;
}
Beispiel #2
0
/*
** Entry point
**
*/
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
{
	// Avoid loading a dll from current directory
	SetDllDirectory(L"");

	CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
	InitCommonControls();

	if (lpCmdLine[0] == L'"')
	{
		// Strip quotes
		++lpCmdLine;
		WCHAR* pos = wcsrchr(lpCmdLine, L'"');
		if (pos)
		{
			*pos = L'\0';
		}
	}

	WCHAR buffer[MAX_PATH];
	GetModuleFileName(hInstance, buffer, MAX_PATH);

	// Remove the module's name from the path
	WCHAR* pos = wcsrchr(buffer, L'\\');
	if (pos)
	{
		*(pos + 1) = L'\0';
	}

	g_Data.programPath = g_Data.settingsPath = buffer;
	wcscat(buffer, L"Rainmeter.ini");

	// Find the settings file and read skins path off it
	if (_waccess(buffer, 0) == 0)
	{
		g_Data.iniFile = buffer;
		if (GetPrivateProfileString(L"Rainmeter", L"SkinPath", L"", buffer, MAX_LINE_LENGTH, buffer) > 0)
		{
			g_Data.skinsPath = buffer;
			if (g_Data.skinsPath.back() != L'\\' && g_Data.skinsPath.back() != L'/')
			{
				g_Data.skinsPath += L'\\';
			}
		}
		else
		{
			g_Data.skinsPath = g_Data.programPath;
			g_Data.skinsPath += L"Skins\\";
		}
	}
	else
	{
		HRESULT hr = SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buffer);
		wcscat(buffer, L"\\Rainmeter\\");
		g_Data.settingsPath = buffer;
		wcscat(buffer, L"Rainmeter.ini");
		g_Data.iniFile = buffer;
		if (SUCCEEDED(hr) && _waccess(buffer, 0) == 0)
		{
			if (GetPrivateProfileString(L"Rainmeter", L"SkinPath", L"", buffer, MAX_LINE_LENGTH, buffer) > 0)
			{
				g_Data.skinsPath = buffer;
				if (g_Data.skinsPath.back() != L'\\' && g_Data.skinsPath.back() != L'/')
				{
					g_Data.skinsPath += L'\\';
				}
			}
			else
			{
				std::wstring error = L"SkinPath not found.\nMake sure that Rainmeter has been run at least once.";
				MessageBox(NULL, error.c_str(), L"Rainmeter Skin Installer", MB_ERROR);
				return 1;
			}
		}
		else
		{
			std::wstring error = L"Rainmeter.ini not found.\nMake sure that Rainmeter has been run at least once.";
			MessageBox(NULL, error.c_str(), L"Rainmeter Skin Installer", MB_ERROR);
			return 1;
		}
	}

	if (_wcsnicmp(lpCmdLine, L"/LoadTheme ", 11) == 0)
	{
		// Skip "/LoadTheme "
		lpCmdLine += 11;

		if (*lpCmdLine && CloseRainmeterIfActive())
		{
			CDialogInstall::LoadTheme(lpCmdLine, true);

			std::wstring file = g_Data.programPath + L"Rainmeter.exe";
			SHELLEXECUTEINFO sei = {0};
			sei.cbSize = sizeof(SHELLEXECUTEINFO);
			sei.fMask = SEE_MASK_UNICODE;
			sei.lpFile = file.c_str();
			sei.lpDirectory = g_Data.programPath.c_str();
			sei.nShow = SW_SHOWNORMAL;
			ShellExecuteEx(&sei);
		}

		return 0;
	}
	else if (wcscmp(lpCmdLine, L"/Packager") == 0)
	{
		CDialogPackage::Create(hInstance, lpCmdLine);
	}
	else
	{
		CDialogInstall::Create(hInstance, lpCmdLine);
	}

	return 0;
}