gcString GetWildcardPath(gcString wildcard)
	{
#ifdef WIN32
		if (Safe::stricmp("PROGRAM_FILES", wildcard.c_str()) == 0)
		{
			wchar_t path[MAX_PATH]  = {0};
			SHGetFolderPathW(NULL, CSIDL_PROGRAM_FILES, NULL, SHGFP_TYPE_CURRENT, path);
			return path;
		}
		else if (Safe::stricmp("DOCUMENTS", wildcard.c_str()) == 0)
		{
			return GetSpecialPath(1);
		}
		else if (Safe::stricmp("JAVA_PATH", wildcard.c_str()) == 0)
		{
			std::string cur = UTIL::WIN::getRegValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\CurrentVersion");

			if (cur.size() > 0)
				return UTIL::WIN::getRegValue(gcString("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\{0}\\JavaHome", cur));
		}
		else if (Safe::stricmp("APP_DATA", wildcard.c_str())==0)
		{
			wchar_t path[MAX_PATH]  = {0};
			SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
			return path;
		}
		else if (Safe::stricmp("USER_APP_DATA", wildcard.c_str())==0)
		{
			return GetSpecialPath(2);
		}
#endif
		return "";
	}
Beispiel #2
0
void DesuraJSSettings::setValue(gcString name, gcString val)
{
	CVar* cvar = GetCVarManager()->findCVar(name.c_str());

	if (cvar && val != gcString(cvar->getString()))
		cvar->setValue(val.c_str());
}
Beispiel #3
0
gcString getRelativePath(const gcString &path)
{
	gcString wd = UTIL::LIN::getAppPath(L"");

	if (path.find(wd) == 0)
		return path.substr(wd.size()+1, std::string::npos);

	return path;
}
Beispiel #4
0
gcString DesuraJSBinding::getThemeColor(gcString name, gcString id)
{
	Color col = GetGCThemeManager()->getColor(name.c_str(), id.c_str());

	char colStr[255];
	Safe::snprintf(colStr, 255, (char*)"#%02X%02X%02X", col.red, col.green, col.blue);

	return gcString(colStr);
}
Beispiel #5
0
static gcTime parseTimeStamp(gcString &str)
{
	//Boost throws exception if no time string. :(
	if (str.find('T') == std::string::npos)
	{
		str = str.substr(0, 8) + "T" + str.substr(8);
	}

	return gcTime::from_iso_string(str);
}
	void AddTool(UserItem* item, gcString name, gcString exe, gcString args, gcString res)
	{
		if (!item)
			return;

		if (name.size() == 0 || exe.size() == 0)
			return;

		item->m_pToolManager->addJSTool(item->m_pItem, item->m_pBranch->getBranchId(), name, exe, args, res);
	}
	void AddTool(UserItem* item, gcString name, gcString exe, gcString args, gcString res)
	{
		if (!item)
			return;

		if (name.size() == 0 || exe.size() == 0)
			return;

		Debug(gcString("Adding JS Tool to {0}: {1} {2} {3}\n", item->m_pItem->getName(), name, exe, args));
		item->m_pToolManager->addJSTool(item->m_pItem, item->m_pBranch->getBranchId(), name, exe, args, res);
	}
Beispiel #8
0
gcString getAbsPath(const gcString& path)
{
	if (path.size() == 0 || path[0] == '/')
		return path;

	gcString wd = UTIL::LIN::getAppPath(L"");

	if (path.find(wd) == std::string::npos)
		return wd + "/" + path;

	return path;
}
Beispiel #9
0
void DesuraJSLinks::loadUrl(int32 tabId, gcString url)
{
	if (tabId == -1)
		return;
	
	if (tabId >= END_PAGE || tabId != ITEMS)
		return;
	
	if (url.size() == 0)
		return;

	g_pMainApp->loadUrl(url.c_str(), (PAGE)tabId);
}
Beispiel #10
0
void CDKProgress::onComplete(gcString& cdKey)
{
	CDKeyForm* keyForm = dynamic_cast<CDKeyForm*>(GetParent());

	if (keyForm)
		keyForm->finish(cdKey.c_str());
}
Beispiel #11
0
void gcWebControl::loadUrl(const gcString& url)
{
	if (m_szHomeUrl == L"about:blank")
		m_szHomeUrl = url;

	m_pChromeBrowser->loadUrl(url.c_str());
}
Beispiel #12
0
bool VSCheckMcf::checkMcf(gcString path)
{
	if (isStopped())
		return false;

	if (!UTIL::FS::isValidFile(UTIL::FS::PathWithFile(path)))
		return false;

	//read file to make sure it is what it says it is
	m_hTempMcf->setFile(path.c_str());

	try
	{
		m_hTempMcf->parseMCF();
	}
	catch (gcException &except)
	{
		Warning("Verify - MCF Error: {0}\n", except);
		return false;
	}

	if (isStopped())
		return false;

	MCFCore::MCFHeaderI *mcfHead = m_hTempMcf->getHeader();

	bool res = (mcfHead && mcfHead->getBuild() == getMcfBuild());

	m_hTempMcf = McfHandle();
	return res;
}
Beispiel #13
0
void BranchInfo::decodeCDKey(gcString cdkey)
{
	m_szCDKey = "";

	if (cdkey.size() == 0)
		return;
	
#ifdef WIN32
	size_t outLen = 0;
	char* raw = (char*)UTIL::STRING::base64_decode(cdkey, outLen);

	std::string reg = UTIL::OS::getConfigValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography\\MachineGuid", true);
	gcString key("{0}_{1}", reg, m_ItemId.toInt64());

	DATA_BLOB db;

	db.pbData = (BYTE*)raw;
	db.cbData = outLen;

	DATA_BLOB secret;
	secret.pbData = (BYTE*)key.c_str();
	secret.cbData = key.size();

	DATA_BLOB out;

	if (CryptUnprotectData(&db, NULL, &secret, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, &out))
		m_szCDKey.assign((char*)out.pbData, out.cbData);

	safe_delete(raw);
#else // TODO
	m_szCDKey = cdkey;
#endif
}
Beispiel #14
0
gcString DesuraJSSettings::getValue(gcString name)
{
	CVar* cvar = GetCVarManager()->findCVar(name.c_str());
	if (!cvar)
		return "";

	return cvar->getExitString();
}
Beispiel #15
0
gcString DesuraJSBinding::getCVarValue(gcString name)
{
	auto cvar = GetCVarManager()->findCVar(name.c_str());

	if (!cvar)
		return "";

	return cvar->getString();
}
Beispiel #16
0
void DownloadTask::onComplete(gcString &savePath)
{
	bool hasError = m_bInError || isStopped();

	if (m_bToolDownloadComplete)
	{
		getUserCore()->getToolManager()->removeTransaction(m_ToolTTID, hasError);
		m_ToolTTID = UINT_MAX;
	}

	if (hasError)
	{
		getItemHandle()->getInternal()->completeStage(true);
		return;
	}

	onCompleteStrEvent(savePath);

	if (getItemInfo()->getCurrentBranch()->isPreOrder())
	{
		getItemInfo()->addSFlag(UserCore::Item::ItemInfoI::STATUS_PRELOADED);
		getItemInfo()->delSFlag(UserCore::Item::ItemInfoI::STATUS_DOWNLOADING);
		getItemHandle()->getInternal()->completeStage(true);
	}
	else if (m_ToolTTID != UINT_MAX)
	{
		UserCore::Misc::ToolTransaction* tt = new UserCore::Misc::ToolTransaction();
		getUserCore()->getToolManager()->updateTransaction(m_ToolTTID, tt);

		getItemHandle()->getInternal()->goToStageDownloadTools(m_ToolTTID, savePath.c_str(), getMcfBranch(), getMcfBuild());
	}
	else
	{
		//mirrored in download tool item task. Make sure to update it as well
		if (HasAllFlags(getItemInfo()->getStatus(), UserCore::Item::ItemInfoI::STATUS_INSTALLCOMPLEX))
		{
			getItemHandle()->getInternal()->goToStageInstallComplex(getMcfBranch(), getMcfBuild());
		}
		else
		{
			getItemHandle()->getInternal()->goToStageInstall(savePath.c_str(), getMcfBranch());
		}
	}
}
Beispiel #17
0
bool FileSystemJSBinding::WriteFile(int32 handle, gcString string)
{
	if (handle < 0 || handle > (int32)m_vFileHandles.size())
		return false;

	auto fh = m_vFileHandles[handle];

	try
	{
		fh->write(string.c_str(), string.size());
		return true;
	}
	catch (gcException &e)
	{
		Warning("Failed to write to file in scriptcore: {0}\n", e);
	}

	return false;
}
Beispiel #18
0
gcRefPtr<UserCore::Item::ItemInfoI> DesuraJSBinding::getItemInfoFromId(gcString szId)
{
	auto im = getItemManager();

	if (!im)
		return nullptr;

	DesuraId id(Safe::atoll(szId.c_str()));
	return im->findItemInfo(id);
}
Beispiel #19
0
void MCFManager::getListOfBadMcfPaths(const gcString &szItemDb, std::vector<MigrateInfo> &delList, std::vector<MigrateInfo> &updateList)
{
	try
	{
		sqlite3x::sqlite3_connection db(szItemDb.c_str());
		getListOfBadMcfPaths(db, delList, updateList);
	}
	catch (std::exception &)
	{
	}
}
Beispiel #20
0
void BranchInstallInfo::extractInstallChecks(const XML::gcXMLElement &icsNode, gcRefPtr<WildcardManager> &pWildCard, std::vector<InsCheck> &vInsChecks)
{
	icsNode.for_each_child("installlocation", [&vInsChecks, pWildCard, this](const XML::gcXMLElement &icNode)
	{
		const gcString iCheck = icNode.GetChild("check");
		const gcString iPath = icNode.GetChild("path");

		if (iCheck.empty() || iPath.empty())
			return;

		try
		{
			gcString strCheckRes = pWildCard->constructPath(iCheck.c_str());

			if (isInstalled())
			{
				if (!updateInstallCheck(strCheckRes, iPath))
					return;

				vInsChecks.push_back(InsCheck(strCheckRes.c_str(), m_szPath.c_str()));
			}
			else
			{
				vInsChecks.push_back(InsCheck(strCheckRes.c_str(), iPath.c_str()));
			}
		}
		catch (...)
		{
		}
	});
}
Beispiel #21
0
gcString DesuraJSBinding::getThemeImage(gcString id)
{
	gcString img = GetGCThemeManager()->getImage(id.c_str());
	gcString path = GetGCThemeManager()->getThemeFolder();

	size_t pos = img.find(path);
	if (pos != std::string::npos)
	{
		img = gcString(".") + img.substr(pos + path.size(), -1);
	}

	return img;
}
Beispiel #22
0
void DesuraJSBinding::setCacheValue(gcString name, gcString value)
{
	gcString fullname("WEBCACHE_{0}", name);
	auto cvar = GetCVarManager()->findCVar(fullname.c_str());

	if (!cvar)
	{
		cvar = gcRefPtr<CVar>::create(fullname.c_str(), "", CFLAG_USER);
		g_pCvarList.push_back(cvar);
	}

	cvar->setValue(value.c_str());
}
Beispiel #23
0
gcString BranchInfo::decodeCDKey(const gcString& strEncodedKey)
{
	if (strEncodedKey.empty())
		return "";

#ifdef WIN32
	std::string reg = UTIL::OS::getConfigValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography\\MachineGuid", true);
	gcString key("{0}_{1}", reg, m_ItemId.toInt64());
#else
	gcString key("{0}", m_ItemId.toInt64());
#endif

	return UTIL::OS::UserDecodeString(key, strEncodedKey);
}
Beispiel #24
0
bool DesuraJSSettings::isValidLinkBinary(gcString path)
{
	if (!UTIL::FS::isValidFile(path))
		return false;

#ifdef WIN32
	return (path.find_last_of(".exe") == path.size()-1);
#else
	char magicBytes[5] = {0};

	try
	{
		UTIL::FS::FileHandle fh(path.c_str(), UTIL::FS::FILE_READ);
		fh.read(magicBytes, 5);
	}
	catch (...)
	{
		return false;
	}

	return UTIL::LIN::getFileType(magicBytes, 5) != UTIL::LIN::BT_UNKNOWN;
#endif
}
void ToolManager::addJSTool(gcRefPtr<UserCore::Item::ItemInfo> item, uint32 branchId, gcString name, gcString exe, gcString args, gcString res)
{
	if (!item)
		return;

	auto branch = item->getBranchById(branchId);

	if (!branch)
		return;

	auto realBranch = gcRefPtr<UserCore::Item::BranchInfo>::dyn_cast(branch);

	if (!realBranch)
		return;

	bool found = false;


	gcRefPtr<JSToolInfo> jsinfo;

	BaseManager<ToolInfo>::for_each([&](gcRefPtr<ToolInfo> info)
	{
		auto temp = gcRefPtr<JSToolInfo>::dyn_cast(info);

		if (!temp)
			return;

		if (item->getId() == temp->getItemId() && name == info->getName() && temp->getBranchId() == branchId)
		{
			jsinfo = temp;
			found = true;
		}
	});

	if (found)
	{
		if (!jsinfo->isRealyInstalled())
			jsinfo->setExePath(exe.c_str());

		return;
	}


	DesuraId toolId(m_iLastCustomToolId, DesuraId::TYPE_TOOL);
	m_iLastCustomToolId--;

	auto tool = gcRefPtr<JSToolInfo>::create(item->getId(), realBranch->getBranchId(), toolId, name, exe, args, res);
	realBranch->addJSTool(toolId);
	addItem(tool);
}
Beispiel #26
0
void ToolManager::addJSTool(UserCore::Item::ItemInfo* item, uint32 branchId, gcString name, gcString exe, gcString args, gcString res)
{
	if (!item)
		return;

	UserCore::Item::BranchInfoI* branch = item->getBranchById(branchId);

	if (!branch)
		return;

	UserCore::Item::BranchInfo* realBranch = dynamic_cast<UserCore::Item::BranchInfo*>(branch);

	if (!realBranch)
		return;

	bool found = false;


	JSToolInfo* jsinfo = nullptr;

	BaseManager<ToolInfo>::for_each([&](ToolInfo* info)
	{
		auto temp = dynamic_cast<JSToolInfo*>(info);

		if (!temp)
			return;

		if (item->getId() == temp->getItemId() && name == info->getName() && temp->getBranchId() == branchId)
		{
			jsinfo = temp;
			found = true;
		}
	});

	if (found)
	{
		if (!jsinfo->isRealyInstalled())
			jsinfo->setExePath(exe.c_str());

		return;
	}


	DesuraId toolId(m_iLastCustomToolId, DesuraId::TYPE_TOOL);
	m_iLastCustomToolId--;

	JSToolInfo* tool = new JSToolInfo(item->getId(), realBranch->getBranchId(), toolId, name, exe, args, res);
	realBranch->addJSTool(toolId);
	addItem(tool);
}
Beispiel #27
0
bool StartUpload(DesuraId id)
{
	Msg("Starting Mcf Upload....\n");

	//start upload
	UserCore::Thread::MCFThreadI* pPrepThread = g_pUserHandle->getThreadManager()->newUploadPrepThread(id, g_strMcfOutPath.c_str());

	*pPrepThread->getErrorEvent() += delegate(&OnStartUploadError);
	*pPrepThread->getCompleteStringEvent() += delegate(&OnStartUploadComplete);

	pPrepThread->start();

	g_WaitCon.wait();

	return g_strUploadHash.size() != 0;
}
Beispiel #28
0
bool CreateMcf(DesuraId id, std::string &strFolderPath)
{
	Msg("Creating Mcf....\n");

	UserCore::Thread::MCFThreadI* pThread = g_pUserHandle->getThreadManager()->newCreateMCFThread(id, strFolderPath.c_str());

	*pThread->getMcfProgressEvent() += delegate(&OnMCFCreateProgress);
	*pThread->getErrorEvent() += delegate(&OnMCFCreateError);
	*pThread->getCompleteStringEvent() += delegate(&OnMCFCreateComplete);

	pThread->start();
	safe_delete(pThread);

	g_WaitCon.wait();

	return g_strMcfOutPath.size() != 0;
}
void CreateProgPage::onComplete(gcString& path)
{
	gcFrame* par = dynamic_cast<gcFrame*>(GetParent());
	gcException eFailCrtMCF(ERR_BADPATH, "Failed to create MCF");
	if (par)
		par->setProgressState(gcFrame::P_NONE);

	if (UTIL::FS::isValidFile(UTIL::FS::PathWithFile(path)))
	{
		CreateMCFForm* temp = dynamic_cast<CreateMCFForm*>(GetParent());

		if (temp)
			temp->showOverView(path.c_str());
	}
	else
	{
		onError(eFailCrtMCF);
	}
}
Beispiel #30
0
void CIPManager::updateItem(DesuraId id, gcString path)
{
	if (path.size() == 0)
	{
		deleteItem(id);
		return;
	}

	try
	{
		sqlite3x::sqlite3_connection db(m_szDBName.c_str());
		sqlite3x::sqlite3_command cmd(db, "REPLACE INTO cip (internalid, path) VALUES (?,?);");

		cmd.bind(1, (long long int)id.toInt64());
		cmd.bind(2, path); 
		cmd.executenonquery();
	}
	catch (std::exception &e)
	{
		Warning("Failed to save cip: {0}\n", e.what());
	}
}