gcString NewAccountDialog::GetRegisterUrl()
{
	return gcString("http://www.{0}/members/register/app", m_szProviderUrl);
}
Example #2
0
LoginForm::LoginForm(wxWindow* parent) : gcFrame(parent, wxID_ANY, Managers::GetString(L"#LF_TITLE"), wxDefaultPosition, wxSize(420,246), wxCAPTION|wxCLOSE_BOX|wxSYSTEM_MENU|wxWANTS_CHARS|wxMINIMIZE_BOX, true)
{
	m_bAutoLogin = false;
	m_pNewAccount = NULL;

	Bind(wxEVT_COMMAND_TEXT_ENTER, &LoginForm::onTextBoxEnter, this);
	Bind(wxEVT_CLOSE_WINDOW, &LoginForm::onClose, this);
	Bind(wxEVT_COMMAND_BUTTON_CLICKED, &LoginForm::onButtonClick, this);
	Bind(wxEVT_MOVE, &LoginForm::onMove, this);


	m_imgLogo = new gcImageControl(this, wxID_ANY, wxDefaultPosition, wxSize( 253,81 ));
	m_imgAvatar = new gcImageControl(this, wxID_ANY, wxDefaultPosition, wxSize( 66,66 ));

	m_imgLogo->setImage("#login_logo");
	m_imgAvatar->setImage("#login_default_avatar");

	m_tbUsername = new gcTextCtrl(this, wxID_ANY, Managers::GetString(L"#LF_USER"), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER|wxWANTS_CHARS);
	m_tbPassword = new gcTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER|wxWANTS_CHARS|wxTE_PASSWORD);
	m_tbPasswordDisp = new gcTextCtrl(this, wxID_ANY, Managers::GetString(L"#LF_PASS"));

#ifndef UI_HIDE_AUTOLOGIN
	m_cbRemPass = new gcCheckBox(this, wxID_ANY, Managers::GetString(L"#LF_AUTO"));
	m_cbRemPass->SetToolTip(Managers::GetString(L"#LF_AUTO_TOOLTIP"));
#endif

	m_butSignin = new gcButton(this, wxID_ANY, Managers::GetString(L"#LOGIN"), wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS);
	m_butCancel = new gcButton(this, wxID_ANY, Managers::GetString(L"#CANCEL"), wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS);

	m_linkOffline = new LoginLink(this, Managers::GetString(L"#LF_OFFLINE"), wxALIGN_LEFT);
	m_linkNewAccount = new LoginLink(this, Managers::GetString(L"#LF_NEWACCOUNT"), wxALIGN_CENTER);
	m_linkLostPassword = new LoginLink( this, Managers::GetString(L"#LF_LOSTPASS"), wxALIGN_RIGHT);

	//focus gets set to the first child. Redirect input to username box
	m_imgLogo->Bind(wxEVT_CHAR, &LoginForm::onFormChar, this);
	m_imgAvatar->Bind(wxEVT_CHAR, &LoginForm::onFormChar, this);

#ifdef WIN32
	Bind(wxEVT_LEFT_UP, &LoginForm::onMouseUp, this);
	Bind(wxEVT_LEFT_DOWN, &LoginForm::onMouseDown, this);
	Bind(wxEVT_MOTION, &LoginForm::onMouseMove, this);

	m_imgLogo->Bind(wxEVT_LEFT_UP, &LoginForm::onMouseUp, this);
	m_imgLogo->Bind(wxEVT_LEFT_DOWN, &LoginForm::onMouseDown, this);
	m_imgLogo->Bind(wxEVT_MOTION, &LoginForm::onMouseMove, this);

	m_imgAvatar->Bind(wxEVT_LEFT_UP, &LoginForm::onMouseUp, this);
	m_imgAvatar->Bind(wxEVT_LEFT_DOWN, &LoginForm::onMouseDown, this);
	m_imgAvatar->Bind(wxEVT_MOTION, &LoginForm::onMouseMove, this);
#endif

	m_tbUsername->Bind(wxEVT_COMMAND_TEXT_UPDATED, &LoginForm::onTextChange, this);
	m_tbUsername->Bind(wxEVT_CHAR, &LoginForm::onChar, this);
	m_tbUsername->Bind(wxEVT_KILL_FOCUS, &LoginForm::onBlur, this);
	m_tbUsername->Bind(wxEVT_SET_FOCUS, &LoginForm::onFocus, this);

	m_tbPassword->Bind(wxEVT_CHAR, &LoginForm::onChar, this);
	m_tbPassword->Bind(wxEVT_KILL_FOCUS, &LoginForm::onBlur, this);

	m_tbPasswordDisp->Bind(wxEVT_COMMAND_TEXT_UPDATED, &LoginForm::onTextChange, this);
	m_tbPasswordDisp->Bind(wxEVT_SET_FOCUS, &LoginForm::onFocus, this);

#ifndef UI_HIDE_AUTOLOGIN
	m_cbRemPass->Bind(wxEVT_CHAR, &LoginForm::onChar, this);
#endif

	m_linkOffline->Bind(wxEVT_CHAR, &LoginForm::onChar, this);
	m_linkNewAccount->Bind(wxEVT_CHAR, &LoginForm::onChar, this);
	m_linkLostPassword->Bind(wxEVT_CHAR, &LoginForm::onChar, this);

	m_linkOffline->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &LoginForm::onLinkClick, this);
	m_linkNewAccount->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &LoginForm::onLinkClick, this);
	m_linkLostPassword->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &LoginForm::onLinkClick, this);


	m_butCancel->Bind(wxEVT_CHAR, &LoginForm::onChar, this);
	m_butSignin->Bind(wxEVT_CHAR, &LoginForm::onChar, this);

	m_tbUsername->SetValue(Managers::GetString(L"#LF_USER"));
	m_tbPasswordDisp->SetValue(Managers::GetString(L"#LF_PASS"));

	m_tbPassword->Show(false);
	m_tbPasswordDisp->Show(true);


	wxFlexGridSizer* fgSizer4 = new wxFlexGridSizer( 1, 3, 0, 0 );
	fgSizer4->AddGrowableCol( 0 );
	fgSizer4->SetFlexibleDirection( wxBOTH );
	fgSizer4->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
	
#ifndef UI_HIDE_AUTOLOGIN
	fgSizer4->Add( m_cbRemPass, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
#else
	fgSizer4->Add(0,0,0,0);
#endif

	fgSizer4->Add( m_butSignin, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );
	fgSizer4->Add( m_butCancel, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );

	
	wxFlexGridSizer* fgSizer5 = new wxFlexGridSizer( 1, 3, 0, 0 );
	fgSizer5->AddGrowableCol( 0 );
	fgSizer5->AddGrowableCol( 1 );
	fgSizer5->AddGrowableCol( 2 );
	fgSizer5->AddGrowableRow( 0 );
	fgSizer5->SetFlexibleDirection( wxBOTH );
	fgSizer5->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
	fgSizer5->Add( m_linkOffline, 0, wxTOP|wxBOTTOM|wxRIGHT, 5 );
	fgSizer5->Add( m_linkNewAccount, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
	fgSizer5->Add( m_linkLostPassword, 0, wxALIGN_RIGHT|wxTOP|wxBOTTOM|wxLEFT, 5 );
	

	wxFlexGridSizer* fgSizer6 = new wxFlexGridSizer( 4, 1, 0, 0 );
	fgSizer6->AddGrowableCol( 0 );
	fgSizer6->SetFlexibleDirection( wxBOTH );
	fgSizer6->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
	fgSizer6->Add( m_tbUsername, 0, wxEXPAND|wxLEFT, 5 );
	fgSizer6->Add( m_tbPassword, 0, wxEXPAND|wxTOP|wxLEFT, 5 );
	fgSizer6->Add( m_tbPasswordDisp, 0, wxEXPAND|wxTOP|wxLEFT, 5 );
	fgSizer6->Add( fgSizer4, 1, wxEXPAND, 5 );

	wxFlexGridSizer* fgSizer3 = new wxFlexGridSizer( 1, 2, 0, 0 );
	fgSizer3->AddGrowableCol( 1 );
	fgSizer3->SetFlexibleDirection( wxBOTH );
	fgSizer3->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
	fgSizer3->Add( m_imgAvatar, 0, 0, 5 );
	fgSizer3->Add( fgSizer6, 1, wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL|wxEXPAND, 5 );


	wxFlexGridSizer* fgSizer2 = new wxFlexGridSizer( 4, 1, 0, 0 );
	fgSizer2->SetFlexibleDirection( wxBOTH );
	fgSizer2->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
	fgSizer2->Add( m_imgLogo, 1, wxTOP|wxBOTTOM|wxALIGN_CENTER_HORIZONTAL, 5 );
	fgSizer2->Add( fgSizer3, 1, wxEXPAND, 5 );
	fgSizer2->Add( 0, 9, 1, wxEXPAND, 5 );
	fgSizer2->Add( fgSizer5, 1, wxEXPAND, 5 );	


	wxFlexGridSizer* fgSizer1 = new wxFlexGridSizer( 1, 3, 0, 0 );
	fgSizer1->AddGrowableCol( 0 );
	fgSizer1->AddGrowableCol( 2 );
	fgSizer1->AddGrowableRow( 0 );
	fgSizer1->SetFlexibleDirection( wxBOTH );
	fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
	fgSizer1->Add( 0, 0, 1, wxEXPAND, 5 );
	fgSizer1->Add( fgSizer2, 1, wxEXPAND, 5 );
	fgSizer1->Add( 0, 0, 1, wxEXPAND, 5 );
	
	this->SetSizer( fgSizer1 );
	this->Layout();


	m_bSavePos = false;

	m_vTabOrder.push_back(m_tbUsername);
	m_vTabOrder.push_back(m_tbPasswordDisp);
	m_vTabOrder.push_back(m_tbPassword);
#ifndef UI_HIDE_AUTOLOGIN
	m_vTabOrder.push_back(m_cbRemPass);
#endif
	m_vTabOrder.push_back(m_butSignin);
	m_vTabOrder.push_back(m_butCancel);
	m_vTabOrder.push_back(m_linkOffline);
	m_vTabOrder.push_back(m_linkNewAccount);
	m_vTabOrder.push_back(m_linkLostPassword);

	Centre(wxCENTRE_ON_SCREEN);
	SetFocus();

	if (gc_login_x.getInt() == -1 || gc_login_y.getInt() == -1)
	{
		int x = wxSystemSettings::GetMetric(wxSYS_SCREEN_X);
		int y = wxSystemSettings::GetMetric(wxSYS_SCREEN_Y);

		int w=0;
		int h=0;
		GetSize(&w, &h);

		int newX = (x-w)/2;
		int newY = (y-h)/2;

		if (newX>0 && newY>0)
			SetSize(newX, newY, -1, -1);
	}
	else
	{
#ifdef NIX
		if (! gc_allow_wm_positioning.getBool())
#endif
			setSavedWindowPos(gc_login_x.getInt(), gc_login_y.getInt(), UINT_MAX, UINT_MAX);
	}

#ifndef UI_HIDE_AUTOLOGIN
	if (gc_savelogin.getBool())
		m_cbRemPass->SetValue(true);
#endif

	if (gc_saveusername.getBool())
	{
		const char* str = gc_lastusername.getString();
		const char* avatar = gc_lastavatar.getString();

		if (gcString(str) != "")
		{
			m_tbUsername->SetValue(str);

			m_tbPasswordDisp->Show(false);
			m_tbPassword->Show();
			m_tbPassword->SetFocus();
			Layout();
		}

		if (avatar && UTIL::FS::isValidFile(UTIL::FS::PathWithFile(avatar)))
			m_imgAvatar->setImage(avatar);
	}

	m_pLogThread = NULL;
	m_bSavePos = true;
	m_bMouseDrag = false;

	onLoginEvent += guiDelegate(this, &LoginForm::onLogin);
	onLoginErrorEvent += guiDelegate(this, &LoginForm::onLoginError);
	onStartLoginEvent += guiDelegate(this, &LoginForm::onStartLogin);

	Managers::LoadTheme(this, "formlogin");
	
#ifndef UI_HIDE_AUTOLOGIN
	Managers::LoadTheme(m_cbRemPass, "formlogin");
#endif

#ifdef WIN32
	SetSize(wxSize(420,246));
#endif

	setFrameRegion();
}
Example #3
0
void User::onNeedWildCardCB(WCSpecialInfo& info)
{
	if (info.handled)
		return;

#ifdef WIN32
	if (Safe::stricmp("PROGRAM_FILES", info.name.c_str()) == 0)
	{
		wchar_t path[MAX_PATH]  = {0};
		SHGetFolderPathW(NULL, CSIDL_PROGRAM_FILES, NULL, SHGFP_TYPE_CURRENT, path);
		info.result = path;
		info.handled = true;
	}
	else if (Safe::stricmp("DOCUMENTS", info.name.c_str()) == 0)
	{
		wchar_t path[MAX_PATH] = {0};
		SHGetFolderPathW(NULL, CSIDL_PERSONAL, NULL, SHGFP_TYPE_CURRENT, path);
		info.result = path;
		info.handled = true;
	}
	else if (Safe::stricmp("JAVA_PATH", info.name.c_str()) == 0)
	{
		std::string cur = UTIL::WIN::getRegValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\CurrentVersion");

		if (cur.size() > 0)
		{
			info.result = UTIL::WIN::getRegValue(gcString("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\{0}\\JavaHome", cur));
			info.handled = true;
		}
	}
	else if (Safe::stricmp("APP_DATA", info.name.c_str())==0)
	{
		wchar_t path[MAX_PATH]  = {0};
		SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
		info.result = path;
		info.handled = true;
	}
	else if (Safe::stricmp("USER_APP_DATA", info.name.c_str())==0)
	{
		wchar_t path[MAX_PATH]  = {0};
		SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
		info.result = path;
		info.handled = true;
	}
#else
	if (Safe::stricmp("XDG_OPEN", info.name.c_str()) == 0)
	{
		info.result = gcString(UTIL::OS::getCurrentDir(L"xdg-open"));
		info.handled = true;
	}
#endif
	else if (Safe::stricmp("APPLICATION", info.name.c_str()) == 0)
	{
#ifdef NIX
		info.result = UTIL::OS::getAppInstallPath();
#else
		info.result = gcString(UTIL::OS::getCurrentDir(DIR_WCOMMON));
#endif
		info.handled = true;
	}
}
Example #4
0
void HGTController::fillDownloadList(bool &usingDiffs)
{
	usingDiffs = false;
	safe_delete(m_vSuperBlockList);
	MCFCore::MCF *webMcf = new MCFCore::MCF();

	try
	{
		webMcf->dlHeaderFromHttp(m_szUrl.c_str());
	}
	catch (gcException &e)
	{
		onErrorEvent(e);
		safe_delete(webMcf);
		return;
	}

	webMcf->sortFileList();

	uint64 mcfOffset = m_pHeader->getSize();
	size_t fsSize = m_rvFileList.size();

	//find the last files offset
	for (size_t x=0; x< fsSize; x++)
	{
		if (!m_rvFileList[x]->isSaved())
			continue;

		if ((m_rvFileList[x]->isComplete() || m_rvFileList[x]->hasStartedDL()) && m_rvFileList[x]->getOffSet() > mcfOffset)
		{
			mcfOffset = m_rvFileList[x]->getOffSet() + m_rvFileList[x]->getCurSize();
		}
	}

	std::deque<Misc::WGTBlock*> vBlockList;
	std::sort(m_rvFileList.begin(), m_rvFileList.end(), SortByOffset);

	for (size_t x=0; x<fsSize; x++)
	{
		//dont download all ready downloaded items
		if (m_rvFileList[x]->isComplete())
			continue;

		//skip files that arnt "saved" in the MCF
		if (!m_rvFileList[x]->isSaved())
			continue;	

		uint32 index = webMcf->findFileIndexByHash(m_rvFileList[x]->getHash());
		auto webFile = webMcf->getFile(index);

		uint64 size = m_rvFileList[x]->getCurSize();
		bool started = m_rvFileList[x]->hasStartedDL();

		if (index == UNKNOWN_ITEM || !webFile || !webFile->isSaved())
		{
			Warning(gcString("File {0} is not in web MCF. Skipping download.\n", m_rvFileList[x]->getName()));

			if (!started)
				m_rvFileList[x]->delFlag(MCFCore::MCFFileI::FLAG_SAVE);

			continue;
		}	


		if (!started)
			m_rvFileList[x]->setOffSet(mcfOffset);


		Misc::WGTBlock* temp = new Misc::WGTBlock;

		temp->fileOffset = m_rvFileList[x]->getOffSet();
		temp->file = m_rvFileList[x];

		if (webFile->hasDiff() && HasAllFlags(m_rvFileList[x]->getFlags(), MCFFileI::FLAG_CANUSEDIFF))
		{
			temp->webOffset = webFile->getDiffOffSet();
			temp->size = webFile->getDiffSize();

			if (!started)
				mcfOffset += webFile->getSize();

			usingDiffs = true;
		}
		else
		{
			m_rvFileList[x]->delFlag(MCFFileI::FLAG_CANUSEDIFF);
			temp->webOffset = webFile->getOffSet();
			temp->size = size;

			if (!started)
				mcfOffset += size;
		}

		vBlockList.push_back(temp);
		m_uiTotal += temp->size;
	}


	std::sort(vBlockList.begin(), vBlockList.end(), &WGTBlockSort);

	while (vBlockList.size() > 0)
	{
		Misc::WGTSuperBlock* sb = new Misc::WGTSuperBlock();
		sb->offset = vBlockList[0]->webOffset;

		do
		{
			Misc::WGTBlock* block = vBlockList.front();
			vBlockList.pop_front();

			sb->size += block->size;
			sb->vBlockList.push_back(block);
		}
		while (vBlockList.size() > 0 && vBlockList[0]->webOffset == (sb->offset + sb->size));

		m_vSuperBlockList.push_back(sb);
	}
}
void WildcardManager::resolveWildCard(WildcardInfo *wcInfo)
{
	if (wcInfo->m_bResolved)
		return;

	if (wcInfo->m_szType == "path" || wcInfo->m_szType == "exe")
	{
		//if (wildcardCheck(wcInfo->m_szPath.c_str()))
		//	Warning("Wildcard check failed on [%s]\n", string);
		char* path = NULL;

		try
		{
			constructPath(wcInfo->m_szPath.c_str(), &path);
			wcInfo->m_szPath = path;
			wcInfo->m_bResolved = true;
		}
		catch (gcException)
		{
		}

		safe_delete(path);
	}
	else if (wcInfo->m_szType == "regkey")
	{
		wcInfo->m_szPath = UTIL::OS::getConfigValue(wcInfo->m_szPath);
		wcInfo->m_bResolved = true;
	}
	else if (wcInfo->m_szType == "regkey64")
	{
		wcInfo->m_szPath = UTIL::OS::getConfigValue(wcInfo->m_szPath, true);
		wcInfo->m_bResolved = true;
	}
	else if (wcInfo->m_szType == "msicheck" || wcInfo->m_szType == "dotnetcheck")
	{
		WCSpecialInfo info;
		info.name = wcInfo->m_szType;
		info.result = wcInfo->m_szPath;

		onNeedInstallSpecialEvent(info);

		if (info.handled)
		{
			wcInfo->m_szPath = info.result;
			wcInfo->m_bResolved = true;
		}
	}
	else if (wcInfo->m_szType == "special")
	{
		if (wcInfo->m_szName == "INSTALL_PATH" || wcInfo->m_szName == "PARENT_INSTALL_PATH")
		{
			wcInfo->m_bResolved = wcInfo->m_szPath.size() > 0;
		}
		else
		{
			WCSpecialInfo info;
			info.name = wcInfo->m_szName;
						
			needSpecial(&info);

			if (info.handled)
			{
				wcInfo->m_szPath = info.result;
				wcInfo->m_bResolved = true;
			}
		}
	}
	else
	{
		Warning(gcString("Unknown Wildcard type: {0}\n", wcInfo->m_szType));
	}
}
Example #6
0
void CIPManager::onRefreshError(gcException& e)
{
	Warning(gcString("Refresh CIP had critical error: {0}\n", e));
	onItemsUpdatedEvent();
	m_bRefreshComplete = true;
}
Example #7
0
void MCF::parseFolder(const char *filePath, const char *oPath)
{
	if (m_bStopped)
		return;

	if (!oPath)
		throw gcException(ERR_BADPATH);


	UTIL::FS::Path path(oPath, "", false);

	if (filePath)
		path += filePath;

	std::vector<UTIL::FS::Path> fileList;
	std::vector<UTIL::FS::Path> dirList;


	if (!UTIL::FS::isValidFolder(path))
		throw gcException(ERR_BADPATH, gcString("The file path was invalid [{0}]", path.getFullPath()));

	UTIL::FS::getAllFiles(path, fileList, NULL);
	UTIL::FS::getAllFolders(path, dirList);

	if (fileList.size() == 0 && dirList.size() == 0)
	{
		MCFCore::MCFFile *temp = new MCFCore::MCFFile();

		if (filePath)
			temp->setPath(filePath);

		temp->setName("%%EMPTYFOLDER%%");
		temp->setDir(oPath);
		temp->setSize(0);

		m_pFileList.push_back(temp);
		return;
	}

	for (size_t x=0; x<fileList.size(); x++)
	{
		std::string file = fileList[x].getFile().getFile();

		if (UTIL::MISC::matchList(file.c_str(), MCFCore::g_vExcludeFileList))
			continue;

		if (file.size() > 0 && file[file.size()-1] == ' ')
			throw gcException(ERR_BADPATH, gcString("File [{0}] has a space at the end of its name. This is not valid for MCF archives.", fileList[x].getFullPath()));

		MCFCore::MCFFile *temp = new MCFCore::MCFFile();

		if (filePath)
			temp->setPath(filePath);
		else
			temp->setPath(DIRS_STR);

		temp->setName(file.c_str());
		temp->setDir(oPath);

		temp->setSize((uint32)UTIL::FS::getFileSize(fileList[x]));

		time_t lastWrite = UTIL::FS::lastWriteTime(fileList[x]);

		std::string timeStr = bpt::to_iso_string(bpt::from_time_t(lastWrite));
		temp->setTimeStamp(UTIL::MISC::atoll(timeStr.c_str()));

		

#ifdef NIX
		std::string fullpath = fileList[x].getFullPath();

		struct stat s;
		if ((stat(fullpath.c_str(), &s) == 0) && s.st_mode & (S_IXUSR|S_IXGRP|S_IXOTH))
			temp->addFlag(MCFFileI::FLAG_XECUTABLE);
#endif

		m_pFileList.push_back( temp );
	}

	for (size_t x=0; x<dirList.size(); x++)
	{
		if (UTIL::MISC::matchList(dirList[x].getLastFolder().c_str(), MCFCore::g_vExcludeDirList))
			continue;

		gcString newPath(dirList[x].getLastFolder().c_str());

		if (filePath)
			newPath = gcString("{0}{1}{2}", filePath, DIRS_STR, dirList[x].getLastFolder());

		parseFolder(newPath.c_str(), oPath);
	}
};
Example #8
0
void IPCToolMain::message(const char* msg)
{
	Msg(gcString("DesuraService: {0}", msg));
}
Example #9
0
void IPCToolMain::debug(const char* msg)
{
	Debug(gcString("DesuraService: {0}", msg));
}	
Example #10
0
void UMcf::setRegValues(const char* szInstallPath)
{
#ifdef WIN32
	char exePath[255];

	if (!szInstallPath)
	{
		GetModuleFileName(nullptr, exePath, 255);

		size_t exePathLen = strlen(exePath);
		for (size_t x = exePathLen; x > 0; x--)
		{
			auto c = exePath[x];
			exePath[x] = '\0';

			if (c == '\\')
				break;
		}

		szInstallPath = exePath;
	}

	if (m_sHeader)
	{
		char appid[100];
		char build[100];

		Safe::snprintf(appid, 100, "%d", m_sHeader->getId());
		Safe::snprintf(build, 100, "%d", m_sHeader->getBuild());

		UTIL::WIN::setRegValue(APPID, appid);
		UTIL::WIN::setRegValue(APPBUILD, build);

		UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\DisplayVersion", gcString("{0}.{1}", appid, build));
		UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\VersionMajor", m_sHeader->getId());
		UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\VersionMinor", m_sHeader->getBuild());
	}

	std::string command = gcString("\"{0}\\desura.exe\" \"{1}\" -urllink", szInstallPath, "%1");

	UTIL::WIN::setRegValue("HKEY_CLASSES_ROOT\\Desura\\", "URL:Desura Protocol");
	UTIL::WIN::setRegValue("HKEY_CLASSES_ROOT\\Desura\\URL Protocol", "");
	UTIL::WIN::setRegValue("HKEY_CLASSES_ROOT\\Desura\\shell\\open\\command\\", command);
	UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Desura\\DesuraApp\\InstallPath", szInstallPath);
	UTIL::WIN::delRegKey("HKEY_LOCAL_MACHINE\\Software\\DesuraNET");

	UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\DisplayName", PRODUCT_NAME);
	UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\UninstallString", gcString("{0}\\Desura_Uninstaller.exe", szInstallPath));
	UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\InstallLocation", szInstallPath);
	UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\DisplayIcon", gcString("{0}\\desura.exe", szInstallPath));
	UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\HelpLink", "http://www.desura.com");
	UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\URLInfoAbout", "http://www.desura.com/about");
	UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\NoRepair", "0");
	UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\NoModify", "1");
	UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\RegCompany", "Desura");
	UTIL::WIN::setRegValue("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Desura\\Publisher", "Desura");

#else
	FILE* fh = fopen("version", "w");

	if (fh)
	{
		fprintf(fh, "BRANCH=%u\nBUILD=%u", m_sHeader->getId(), (uint32)m_sHeader->getBuild());
		fclose(fh);
	}
	else
	{
		ERROR_OUTPUT("Failed to open version file to write version info.");
	}
#endif
}
Example #11
0
void IPCToolMain::warning(const char* msg)
{
	Warning(gcString("DesuraService: {0}", msg));
}
Example #12
0
void UMcf::install(const wchar_t* path)
{
	m_bCanceled = false;
	FileHandle fh(m_szFile.c_str(), m_uiOffset);

	if (!fh.isValid())
		throw gcException(ERR_INVALIDFILE, GetLastError(), gcString("Failed to open update file {0}.", m_szFile));

#ifdef WIN32
	if (m_bShouldMoveOldFiles)
		removeOldFiles(path);
#endif

	//sort by offset so we are not seeking all over the place
	std::sort(m_pFileList.begin(), m_pFileList.end(), &SortMcfFiles);

	m_uiTotProgress = 0;
	m_uiCurProgress = 0;

	for (size_t x=0; x<m_pFileList.size(); x++)
	{
		if (m_pFileList[x]->isCompressed())
			m_uiTotProgress += m_pFileList[x]->getCSize();
		else
			m_uiTotProgress += m_pFileList[x]->getSize();
	}

	for(size_t x=0; x<m_pFileList.size(); x++)
	{
		if (m_bCanceled)
			throw gcException(ERR_USERCANCELED);

		if (!m_pFileList[x] || !m_pFileList[x]->isSaved())
			continue;

#ifdef WIN32
		if (m_bShouldMoveOldFiles)
			moveOldFiles(path, m_pFileList[x]->getName());
#else
		m_pFileList[x]->remove(path);
#endif

		uint8 res = m_pFileList[x]->readMCFAndSave(fh.hFileSrc, path?path:L".\\", m_uiOffset, delegate(this, &UMcf::onFileProgress));
		
		if (m_bCanceled)
			throw gcException(ERR_USERCANCELED);
			
		if (res == MCFF_ERR_BADHASH)
			throw gcException(ERR_CSUM_FAILED, gcString("Check sum failed on file {0}\\{1}", m_pFileList[x]->getPath(), m_pFileList[x]->getName()));

		if (res == MCFF_ERR_INVALIDHANDLE)
			throw gcException(ERR_INVALID, gcString("Could not open file {0}\\{1} for updating. Sys Code: {2}", m_pFileList[x]->getPath(), m_pFileList[x]->getName(), GetLastError()));

		if (res != 0 && res != MCF_NOTCOMPRESSED)
			throw gcException(ERR_INVALID, gcString("Failed to update file {0}\\{1}: {2}.", m_pFileList[x]->getPath(), m_pFileList[x]->getName(), (uint32)res));

		if (m_pFileList[x]->isCompressed())
			m_uiCurProgress += m_pFileList[x]->getCSize();
		else
			m_uiCurProgress += m_pFileList[x]->getSize();
	}
}
Example #13
0
PipeClient::PipeClient(const char* name, LoopbackProcessor* loopbackProcessor, uint32 managerId) : PipeBase(name, gcString("{0}- IPC Client",name).c_str()), IPCManager(loopbackProcessor, managerId, name)
{
	setSendEvent(&m_WaitCond);
}
gcString NewAccountDialog::GetTermsUrl()
{
	return gcString("http://www.{0}/app/terms", m_szProviderUrl);
}
Example #15
0
void startService(const char* szName, std::vector<std::string> &args)
{
	assert(szName);
	gcWString wName(szName);

	SC_HANDLE scm, Service;
	SERVICE_STATUS ssStatus; 
	DWORD dwWaitTime;
	
	//open connection to SCM
	scm = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);

	if (!scm)
		throw gcException(ERR_NULLSCMANAGER, GetLastError(), "Failed to open the Service Control Manager");

	//open service
	Service = OpenService(scm, wName.c_str(), SERVICE_START|SERVICE_QUERY_STATUS);
	if (!Service)
	{
		CloseServiceHandle(scm);
		throw gcException(ERR_NULLSERVICE, GetLastError(), gcString("Failed to open service: {0}", szName));
	}

	// Check the status until the service is no longer start pending. 
	if (!QueryServiceStatus( Service, &ssStatus) )
	{
		CloseServiceHandle(Service);
		CloseServiceHandle(scm);
		throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to Query service: {0}", szName));
	}

	while (ssStatus.dwCurrentState == SERVICE_STOP_PENDING)
	{
		gcSleep(1000);
	}

	if (ssStatus.dwCurrentState != SERVICE_STOPPED) 
	{
		CloseServiceHandle(Service);
		CloseServiceHandle(scm);
		throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to start service: Service {0} is not stopped [{1}]", szName, ssStatus.dwCurrentState));
	}

	BOOL res = doStartService(Service, szName, args);

	if (res == 0)
	{
		if (GetLastError() == 1058)
			throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to start service {0} as the service is disabled. Please use msconfig and renable service.", szName));

		throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to start service: {0}", szName));
	}

	// Check the status until the service is no longer start pending. 
	if (!QueryServiceStatus( Service, &ssStatus) )
	{
		CloseServiceHandle(Service);
		CloseServiceHandle(scm);
		throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to Query service: {0}", szName));
	}
		
	DWORD totalTime = 0;

	while (ssStatus.dwCurrentState != SERVICE_RUNNING) 
	{ 
		if (ssStatus.dwCurrentState == SERVICE_STOPPED)
		{
			//start service
			BOOL res = doStartService(Service, szName, args);

			if (res == 0)
				throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to start service: {0}", szName));
		}

		dwWaitTime = 1000;
		totalTime += dwWaitTime;

		gcSleep( dwWaitTime );

		// Check the status again. 
		if (!QueryServiceStatus( Service, &ssStatus) )
		{
			CloseServiceHandle(Service);
			CloseServiceHandle(scm);
			throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to Query service: {0}", szName));
		}

		if (totalTime > 30000)
		{
			CloseServiceHandle(Service);
			CloseServiceHandle(scm);
			throw gcException(ERR_SERVICE, gcString("Service {0} Startup timed out after 30 seconds.", szName));
		}
	}
		
	// Check the status again. 
	if (!QueryServiceStatus( Service, &ssStatus) )
	{
		CloseServiceHandle(Service);
		CloseServiceHandle(scm);
		throw gcException(ERR_SERVICE, GetLastError(), gcString("Failed to Query service: {0}", szName));
	}

	CloseServiceHandle(scm);
	CloseServiceHandle(Service); 

	if (ssStatus.dwCurrentState != SERVICE_RUNNING) 
		throw gcException(ERR_SERVICE, gcString("Failed to start service: {0} [{1}]", szName, ssStatus.dwCurrentState));
}
Example #16
0
void EventHandler::onLogConsoleMsg(const char* message, const char* source, int line)
{
	if (gc_enablebrowserconsole.getBool())
		Warning(gcString("Webkit: {0} [{1} : {2}]\n", message, source, line));
}
Example #17
0
void changeServiceAccess(const char* szName)
{
	assert(szName);

	SC_HANDLE scm = NULL;
	SC_HANDLE Service = NULL;

	BOOL                 bDaclPresent   = FALSE;
	BOOL                 bDaclDefaulted = FALSE;
	DWORD                dwSize         = 0;
	EXPLICIT_ACCESS      ea;
	PACL                 pacl           = NULL;
	PACL                 pNewAcl        = NULL;
	PSECURITY_DESCRIPTOR psd            = NULL;
	SECURITY_DESCRIPTOR  sd;


	//open connection to SCM
	scm = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);

	if (!scm)
		throw gcException(ERR_NULLSCMANAGER, GetLastError(), "Failed to open the Service Control Manager");

	gcWString wName(szName);

	try
	{
		//open service
		Service = OpenService(scm, wName.c_str(), READ_CONTROL|WRITE_DAC);
		if (!Service)
			throw gcException(ERR_NULLSERVICE, GetLastError(), gcString("Failed to open service: {0}", szName));


		// Get the current security descriptor.
		if (!QueryServiceObjectSecurity(Service, DACL_SECURITY_INFORMATION, psd, 0, &dwSize))
		{
			if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
			{
				psd = (PSECURITY_DESCRIPTOR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize);

				if (!psd)
					throw gcException(ERR_SERVICE, gcString("Failed heap allocation for service service: {0}", szName));

				//get securtty info
				if (!QueryServiceObjectSecurity(Service, DACL_SECURITY_INFORMATION, psd, dwSize, &dwSize))
					throw gcException(ERR_SERVICE, GetLastError(), gcString("QueryServiceObjectSecurity failed for service: {0}", szName));
			}
		}

		if (!psd)
			throw gcException(ERR_SERVICE, gcString("Failed heap allocation for service service: {0}", szName));

		// Get the DACL.
		if (!GetSecurityDescriptorDacl(psd, &bDaclPresent, &pacl, &bDaclDefaulted))		
			throw gcException(ERR_SERVICE, GetLastError(), gcString("GetSecurityDescriptorDacl failed for service: {0}", szName));


		DWORD SidSize;
		PSID TheSID;

		SidSize = SECURITY_MAX_SID_SIZE;
		// Allocate enough memory for the largest possible SID.
		if(!(TheSID = LocalAlloc(LMEM_FIXED, SidSize)))
		{    
			LocalFree(TheSID);
			throw gcException(ERR_SERVICE, GetLastError(), gcString("LocalAlloc failed for  service: {0}", szName));
		}

		if(!CreateWellKnownSid(WinWorldSid, NULL, TheSID, &SidSize))
		{
			LocalFree(TheSID);
			throw gcException(ERR_SERVICE, GetLastError(), gcString("CreateWellKnownSid failed for  service: {0}", szName));
		}

		wchar_t everyone[255];
		wchar_t domain[255];
		DWORD eSize = 255;
		DWORD dSize = 255;
		SID_NAME_USE rSidNameUse;

		if (!LookupAccountSid(NULL, TheSID, everyone, &eSize, domain, &dSize, &rSidNameUse))
		{
			LocalFree(TheSID);
			throw gcException(ERR_SERVICE, GetLastError(), gcString("LookupAccountSid failed for  service: {0}", szName));
		}

		LocalFree(TheSID);

		// Build the ACE.
		BuildExplicitAccessWithName(&ea, everyone, SERVICE_START|SERVICE_STOP|READ_CONTROL|SERVICE_QUERY_STATUS|PROCESS_QUERY_INFORMATION, SET_ACCESS, NO_INHERITANCE);

		if (SetEntriesInAcl(1, &ea, pacl, &pNewAcl) != ERROR_SUCCESS)
		{
			throw gcException(ERR_SERVICE, GetLastError(), gcString("SetEntriesInAcl failed for  service: {0}", szName));
		}

		// Initialize a NEW Security Descriptor.
		if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION))			
			throw gcException(ERR_SERVICE, GetLastError(), gcString("InitializeSecurityDescriptor failed for  service: {0}", szName));

		// Set the new DACL in the Security Descriptor.
		if (!SetSecurityDescriptorDacl(&sd, TRUE, pNewAcl, FALSE))						
			throw gcException(ERR_SERVICE, GetLastError(), gcString("SetSecurityDescriptorDacl failed for  service: {0}", szName));

		// Set the new DACL for the service object.
		if (!SetServiceObjectSecurity(Service, DACL_SECURITY_INFORMATION, &sd))		
			throw gcException(ERR_SERVICE, GetLastError(), gcString("SetServiceObjectSecurity failed for  service: {0}", szName));

	}
	catch (gcException &e)
	{
		if (Service)
			CloseServiceHandle(Service);

		if (scm)
			CloseServiceHandle(scm);

		// Free buffers.
		LocalFree((HLOCAL)pNewAcl);
		HeapFree(GetProcessHeap(), 0, (LPVOID)psd);

		throw e;
	}

	CloseServiceHandle(scm);
	CloseServiceHandle(Service);

	// Free buffers.
	LocalFree((HLOCAL)pNewAcl);
	HeapFree(GetProcessHeap(), 0, (LPVOID)psd);
}
Example #18
0
	void OnMCFCreateError(gcException &e)
	{
		Warning(gcString("Failed to create mcf: {0}", e));
		g_WaitCon.notify();
	}
Example #19
0
void MCF::dlHeaderFromWeb()
{
	if (m_bStopped)
		return;

	if (m_vProviderList.size() == 0)
		throw gcException(ERR_ZEROFILE);

	gcException lastE;
	bool successful = false;

	OutBuffer out(MCF_HEADERSIZE_V2);
	MCFCore::Misc::MCFServerCon msc;

	for (size_t x=0; x<m_vProviderList.size(); x++)
	{
		try
		{
			msc.disconnect();
			msc.connect(m_vProviderList[x]->getUrl(), m_pFileAuth);

			msc.downloadRange(0, 5, &out); //4 id bytes and 1 version byte

			if (out.m_uiTotalSize != 5)
				throw gcException(ERR_BADHEADER, "Did not get any data from mcf server.");

			const char* data = out.m_szBuffer;

			if ( !(data[0] == 'L' && data[1] == 'M' && data[2] == 'C' && data[3] == 'F') )
				throw gcException(ERR_BADHEADER, "Failed magic check.");

			size_t headerSize = MCF_HEADERSIZE_V1;

			if (data[4] == 0x01)
				headerSize = MCF_HEADERSIZE_V1;
			else if (data[4] == 0x02)
				headerSize = MCF_HEADERSIZE_V2;
			else
				throw gcException(ERR_BADHEADER, "Bad version number");

			out.reset();
			msc.downloadRange(0, headerSize, &out);

			if (out.m_uiTotalSize != headerSize)
				throw gcException(ERR_BADHEADER, "Did not get correct ammount of data from server.");

			MCFCore::MCFHeader webHeader((uint8*)out.m_szBuffer);

			if (!webHeader.isValid())
				throw gcException(ERR_BADHEADER, "Mcf header was not valid.");

			uint32 ths = webHeader.getXmlSize();
			out = ths;

			msc.downloadRange(webHeader.getXmlStart(), webHeader.getXmlSize(), &out);

			if (out.m_uiTotalSize == 0 || out.m_uiTotalSize != webHeader.getXmlSize())
				throw gcException(ERR_WEBDL_FAILED, "Failed to download MCF xml from web (size is ether zero or didnt match header size)");

			data = out.m_szBuffer;

			if (data[0] == 'L' && data[1] == 'M' && data[2] == 'C' && data[3] == 'F')
				throw gcException(ERR_WEBDL_FAILED, "Server failed 4gb seek.");

			setHeader(&webHeader);
			successful = true;
			break;

		}
		catch (gcException &e)
		{
			lastE = e;
			Warning(gcString("Failed to download MCF Header from {1}: {0}\n", e, m_vProviderList[x]->getUrl()));
		}
	}

	if (!successful)
		throw lastE;

	uint32 bz2BuffLen = getHeader()->getXmlSize()*25;
	char* bz2Buff = NULL;

	if ( isCompressed() )
	{
		bz2Buff = new char[bz2BuffLen];
		UTIL::STRING::zeroBuffer(bz2Buff, bz2BuffLen);

		try
		{
			UTIL::BZIP::BZ2DBuff((char*)bz2Buff, &bz2BuffLen, out.m_szBuffer, out.m_uiTotalSize);
			parseXml(bz2Buff, bz2BuffLen);
			safe_delete(bz2Buff);
		}
		catch (gcException &)
		{
			safe_delete(bz2Buff);
			throw;
		}
	}
	else
	{
		parseXml(out.m_szBuffer, out.m_uiTotalSize);
	}

	//we remove the complete flag due to the files not existing in the MCF
	for (size_t x=0; x< m_pFileList.size(); x++)
	{
		m_pFileList[x]->delFlag(MCFCore::MCFFileI::FLAG_COMPLETE);
	}

	if (m_szFile != "")
		saveMCF_Header();
}
Example #20
0
	void OnUploadError(gcException &e)
	{
		Warning(gcString("Failed to upload of mcf: {0}", e));
		g_WaitCon.notify();
	}
void ToolManager::findJSTools(UserCore::Item::ItemInfo* item)
{
	bool validPath = false;

	for (size_t x=0; x<item->getBranchCount(); x++)
	{
		gcString path = item->getBranch(x)->getInstallScriptPath();

		if (UTIL::FS::isValidFile(path))
			validPath = true;
	}

	if (!validPath)
		return;

	m_ScriptLock.lock();
	
	if (!m_pFactory)
	{
		Warning("Failed to load scriptcore for find JS Tools\n");
		m_ScriptLock.unlock();
		return;
	}

	m_uiInstanceCount++;
	m_ScriptLock.unlock();

	for (size_t x=0; x<item->getBranchCount(); x++)
	{
		gcString path = item->getBranch(x)->getInstallScriptPath();

		if (!UTIL::FS::isValidFile(path))
			continue;

		ScriptCoreI* instance = (ScriptCoreI*)m_pFactory(SCRIPT_CORE);

		UserItem* userItem = new UserItem();
		userItem->m_pItem = item;
		userItem->m_pBranch = item->getBranch(x);
		userItem->m_pToolManager = this;

		try
		{
			instance->setItem(userItem);
			instance->executeScript(path.c_str());
			instance->executeString("ToolSetup();");
		}
		catch (gcException &e)
		{
			gcString errMsg(e.getErrMsg());

			if (errMsg.find("ToolSetup is not defined") == std::string::npos)
				Warning(gcString("Failed to execute toolsetup: {0}\n", e));
		}

		instance->destory();
	}

	m_ScriptLock.lock();
	m_uiInstanceCount--;
	m_ScriptLock.unlock();

	if (m_uiInstanceCount == 0)
		unloadJSEngine();
}
Example #22
0
gcString DesuraJSUploadInfo::getUploadId(UserCore::Misc::UploadInfoThreadI* upload)
{
	return gcString("{0}", upload->getHash());
}
Example #23
0
void HtmlTabPage::onFullSearch(gcString &text)
{
	if (m_pWebControl)
		m_pWebControl->executeJScript(gcString("if(typeof onDesuraFullSearch == 'function'){onDesuraFullSearch('{0}', '{1}');}", text, g_szSearchArea[m_SearchArea]).c_str());
}
	PassReminderThread(const char* email) : BaseThread("Password Reminder Thread")
	{
		m_szEmail = gcString(email);
	}
Example #25
0
void WildcardManager::constructPath(const char* path, char **res, uint8 *depth)
{
	if (!path)
		throw gcException(ERR_BADPATH);

	(*depth)++;

	if (*depth > 25)
		throw gcException(ERR_WILDCARD, "Hit max recursion while constructing path (posible loop).");

	size_t len = strlen(path);

	int32 start = -1;
	int32 stop = 0;

	std::vector<char*> list;
	AutoDeleteV<std::vector<char*>> lad(list);

	//split the string up into section based on %% and then add to vector
	for (size_t x=0; x<len; x++)
	{
		if (path[x] == '%')
		{
			if (x==0)
			{
				start = 0;
			}
			else if (start == -1)
			{
				start = (int32)x;
		
				char* temp = new char[start-stop+1];
				for (int32 y=stop; y<=start; y++)
					temp[y-stop] = path[y];

				temp[start-stop] = '\0';
				list.push_back(temp);
			}
			else
			{
				stop = (int32)x;

				char *temp = new char[stop-start+1];
				for (int32 y = start; y<=stop; y++)
					temp[y-start] = path[y];

				temp[stop-start] = '\0';

				list.push_back(temp);
				start = -1;
				stop++;
			}

		}
		else if (x>=len-1)
		{
			char* temp = new char[len-stop+1];
			for (int32 y=stop; y<(int32)len; y++)
				temp[y-stop] = path[y];

			temp[len-stop] = '\0';

			list.push_back(temp);
		}
	}

	//all those starting with % are wildcards so resolve them
	for (size_t x=0; x<list.size(); x++)
	{
		if (list[x][0] == '%')
		{
			size_t len = strlen(list[x]);
			char *temp = new char[len];
			for (size_t y=1; y<len; y++)
				temp[y-1] = list[x][y];
			temp[len-1]='\0';

			if (strlen(temp)==0)
			{
			  delete [] temp;
				throw gcException(ERR_WILDCARD, gcString("Failed to find wildcard [{0}] Current node is null", path));
			}

			AutoDelete<char> tad(temp);
			AutoDelete<WildcardInfo> wad;

			WildcardInfo* wcInfo = NULL;

			if (Safe::stricmp(temp, "TEMP") == 0)
			{
				WCSpecialInfo info;
				info.name = "temp";
				onNeedInstallSpecialEvent(info);

				if (info.handled)
				{
					wcInfo = new WildcardInfo("temp", info.result.c_str(), "temp", true);
					AutoDelete<WildcardInfo> ad(wcInfo);
					wad = ad;
				}
			}
			else
			{
				wcInfo = findItem(temp);
			}

			if (!wcInfo)
				throw gcException(ERR_WILDCARD, gcString("Failed to find wildcard [{0}]", temp));

			resolveWildCard(wcInfo);

			if (!wcInfo->m_bResolved)
				throw gcException(ERR_WILDCARD, gcString("Failed to resolve wildcard [{0}]", temp));

			if (wcInfo->m_szPath == temp)
			{
				//dont do any thing, dont have enough info yet.
				size_t len = strlen(temp)+3;
				char* newPath = new char[len];
				Safe::snprintf(newPath, len, "%%%s%%", temp);

				safe_delete(list[x]);
				list[x] = newPath;
			}
			else if (wcInfo->m_szPath != "")
			{
				char* newPath = NULL;

				constructPath(wcInfo->m_szPath.c_str(), &newPath, depth);

				safe_delete(list[x]);
				list[x] = newPath;

				if (Safe::stricmp(temp, "TEMP") != 0)
				{
					//this means we dont have to resolve this path next time
					wcInfo->m_szPath = newPath;
				}
			}
			else
			{
				throw gcException(ERR_WILDCARD, gcString("Failed to find wildcard [{0}]", temp));
			}
		}
	}

	size_t totalLen = 0;
	size_t listSize = list.size();

	for (size_t x=0; x<listSize; x++)
		totalLen += strlen(list[x]);

	safe_delete(*res);

	*res = new char[totalLen+1];
	char* cur = *res;

	//put list back into one stting;
	for (size_t x=0; x<listSize; x++)
	{
		size_t itemLen = strlen(list[x]);
		strncpy(cur, list[x], itemLen);
		cur += itemLen;
	}

	(*res)[totalLen] = '\0';
	(*depth)--;
}
Example #26
0
void DownloadToolTask::onDLError(gcException &e)
{
	//Dont worry about errors here. We will sort them out on launch
	Warning(gcString("Failed to download tool: {0}\n", e));
}
//this is a feature of webcore but we need it here in case we need to shutdown during a download
void DownloadUpdateTask::downloadUpdate()
{
#ifdef DEBUG
	return;
#endif

	uint32 appver = m_uiAppVer;
	uint32 appbuild = m_uiAppBuild;


	HttpHandle wc(PRIMUPDATE);
	getWebCore()->setWCCookies(wc);
	
	wc->addPostText("appid", appver);
	wc->postWeb();


	if (wc->getDataSize() == 0)
		throw gcException(ERR_INVALIDDATA);


	XML::gcXMLDocument doc(const_cast<char*>(wc->getData()), wc->getDataSize());
	doc.ProcessStatus("appupdate");

	auto mNode = doc.GetRoot("appupdate").FirstChildElement("mcf");

	if (!mNode.IsValid())
		throw gcException(ERR_BADXML);

	uint32 version = 0;
	uint32 build = 0;
	
	mNode.GetAtt("appid", version);
	mNode.GetAtt("build", build);

	if (version == 0 || build == 0)
		throw gcException(ERR_BADXML);

	//check to see if its newer than last
	if (appbuild != 0 && build <= appbuild && appver == version)
		return;

	gcString url = mNode.GetChild("url");

	if (url.size() == 0)
		throw gcException(ERR_BADXML);

#ifdef WIN32
	const char *comAppPath = getUserCore()->getAppDataPath();
	m_szPath = gcString("{0}{1}{2}", comAppPath, DIRS_STR, UPDATEFILE);
#else
	m_szPath = gcString("{0}", UPDATEFILE);
#endif

	m_hMcfHandle->setFile(m_szPath.c_str());
	m_hMcfHandle->setWorkerCount(1);
	
	try
	{
		m_hMcfHandle->dlHeaderFromHttp(url.c_str());

#ifdef WIN32
		const char* dir = ".\\";
#else
		const char* dir = "./";
#endif

		//Dont use courgette for non admins for now
		bool useCourgette = false;

#ifdef WIN32
		if (getUserCore()->isAdmin())
			useCourgette = true;
#endif

		bool res = m_hMcfHandle->verifyInstall(dir, true, useCourgette);

		m_hMcfHandle->getProgEvent() += delegate(this, &DownloadUpdateTask::onDownloadProgress);

		UserCore::Misc::update_s info;
		info.build = build;

		if (!res)
		{
			Msg(gcString("Downloading " PRODUCT_NAME " update: Ver {0} build {1}\n", appver, build));
			info.alert = true;

			onDownloadStartEvent(info);

			if (useCourgette)
				m_hMcfHandle->dlFilesFromHttp(url.c_str(), dir);
			else
				m_hMcfHandle->dlFilesFromHttp(url.c_str());

			if (!isStopped())
				onDownloadCompleteEvent(info);
		}
		else
		{
			//sometimes this gets called after shutdown and causes major problems
			if (!getUserCore() || !getUserCore()->getServiceMain())
				return;

			gcString av("{0}", appver);
			gcString ab("{0}", build);
			info.alert = false;

			try
			{
				getUserCore()->getServiceMain()->updateRegKey(APPID, av.c_str());
				getUserCore()->getServiceMain()->updateRegKey(APPBUILD, ab.c_str());
			}
			catch (gcException &e)
			{
				Warning(gcString("Failed to update reg key: {0}\n", e));
			}

			onDownloadCompleteEvent(info);
		}
	}
	catch (gcException &e)
	{
		Warning(gcString("Download update failed: {0}\n", e));
	}
}
Example #28
0
void CVarManager::loadUser(CVar* var)
{
	loadCVarFromDb(var, "SELECT value FROM cvaruser WHERE name=? AND user=?;", gcString("{0}", m_uiUserId));
}
Example #29
0
void User::setAvatarPath(const char* path)
{
	m_szAvatar = gcString(path);
	onNewAvatarEvent(m_szAvatar);
}
Example #30
0
void ToolManager::onSpecialCheck(WCSpecialInfo &info)
{
	if (info.name == "msicheck")
	{
		info.handled = true;

		if (UTIL::WIN::isMsiInstalled(info.result.c_str()))
		{
			UTIL::FS::Path filePath(m_pUser->getAppDataPath(), "", false);

			filePath += "tools";
			filePath += "installcheck";

			UTIL::FS::recMakeFolder(filePath);
			filePath += UTIL::FS::File(info.result);

			try
			{
				UTIL::FS::FileHandle fh(filePath, UTIL::FS::FILE_WRITE);
				fh.write("installed", 9);
				fh.close();

				info.result = filePath.getFullPath();
			}
			catch (gcException)
			{
				Warning(gcString("Failed to open file {0} for Tool Msi Check.", filePath.getFullPath()));
			}
		}
		else
		{
			info.result = "!! Not Installed !!";
		}
	}
	else if (info.name == "javacheck")
	{
		info.handled = true;

		std::string cur = UTIL::WIN::getRegValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\CurrentVersion");
		std::string home = UTIL::WIN::getRegValue(gcString("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\{0}\\JavaHome", cur));

		char szJ[2] = {0};
		szJ[0] = home.back();

		uint32 cVer = Safe::atoi(info.result.c_str());
		uint32 jVer = Safe::atoi(szJ);

		if (cVer != 0 && cVer >= jVer)
			info.result = home;
		else
			info.result = "!! Not Installed !!";
	}
	else if (info.name == "dotnetcheck")
	{
		info.handled = true;

		std::vector<std::string> list;
		UTIL::STRING::tokenize(info.result, list, ".");

		uint32 major = 0;
		uint32 minor = 0;
		bool client = false;

		if (list.size() >= 1)
			major = Safe::atoi(list[0].c_str());
		if (list.size() >= 2)
			minor = Safe::atoi(list[1].c_str());
		if (list.size() >= 3)
			client = list[2] == "c";

		if (UTIL::WIN::isDotNetVersionInstalled(major, minor, client))
		{
			UTIL::FS::Path filePath(m_pUser->getAppDataPath(), "", false);

			filePath += "tools";
			filePath += "installcheck";

			UTIL::FS::recMakeFolder(filePath);
			filePath += UTIL::FS::File(gcString("dot_net_") + info.result);

			try
			{
				UTIL::FS::FileHandle fh(filePath, UTIL::FS::FILE_WRITE);
				fh.write("installed", 9);
				fh.close();

				info.result = filePath.getFullPath();
			}
			catch (gcException)
			{
				Warning(gcString("Failed to open file {0} for Tool .Net Check.", filePath.getFullPath()));
			}
		}
		else
		{
			info.result = "!! Not Installed !!";
		}
	}
	else if (info.name == "temp")
	{
		UTIL::FS::Path path(m_pUser->getAppDataPath(), "", false);
		path += "temp";
		
		time_t t = time(nullptr) + GetTickCount();
		gcSleep(1000);
		path += gcString("{0}", t);

		UTIL::FS::recMakeFolder(path);

		info.result = path.getFullPath();
		info.handled = true;
	}
}