Ejemplo n.º 1
0
	MojErr handle0Cancel()
	{
		handle0();
		m_slot0Cancel.cancel();
		return MojErrNone;
	}
Ejemplo n.º 2
0
bool ABPLTools::DownloadAndLaunch(Options options)
{
	bool bResult=false;
	CString appLocal = GetWorkingFolder();
	CString server = MakeCanonical(options.m_server);	// Build URL
	// Find application
	CString xmlName[] = { "trayItem.jnlp", "tms_local.jnlp", "retailMonitor.jnlp", "trniviewer.jnlp" };
	ApplicationInfo application;
	CString appName = xmlName[options.m_application];
	application.LoadXML(server + "apps/" + appName);
	//int idx = appName.ReverseFind('/');
	//CString file = appName.Mid(idx+1);
	//tools.DownloadFile(server + "apps/" + appName, appLocal + file);

	std::vector<CString> resources, resources32, resources64, resourcesMac;
	for (int i=0; i<(int)application.m_extension.size(); i++)
	{
		CString thirdParty = DownloadString(server + application.m_extension[i]);
		// tools.DownloadFile(server + application.m_extension[i], appLocal + "thirdParty.xml");
		TiXmlElement* element;
		TiXmlDocument doc1;
		doc1.Parse(thirdParty);
		TiXmlHandle handle0(&doc1);
		int idx=0;
		do
		{
			TiXmlHandle handle1 = handle0.FirstChild("jnlp").Child("resources", idx++);
			element = handle1.ToElement();
			if (element)
			{
				std::vector<CString> *pVector = &resources;
				const char *os = element->Attribute("os");
				const char *arch = element->Attribute("arch");
				const char *family = element->Attribute("family");
				
				if (os)
				{
					if (!strcmp(os, "Windows"))
					{
						if (arch)
						{
							if (!strcmp(arch, "x86"))
								pVector = &resources32;
							else if (!strcmp(arch, "x86_64"))
								pVector = &resources64;
						}
					}

					if (strstr(os, "Mac"))
					{
						pVector = &resourcesMac;
					}

				}
			
				if (!family)
				{
					int idx2=0;
					TiXmlElement* element2;
					do
					{
						element2 = handle1.Child("jar", idx2++).ToElement();
						if (element2)
							pVector->push_back(element2->Attribute("href"));
					}
					while (element2);
				}

			}
		}  while (element);
	}

	std::vector<CString> downloadList;
	std::copy(resources.begin(), resources.end(), std::back_inserter(downloadList));
	std::copy(resources32.begin(), resources32.end(), std::back_inserter(downloadList));
	std::copy(application.m_jars.begin(), application.m_jars.end(), std::back_inserter(downloadList));
	CString fileServer = server;
	fileServer.Replace("/", "_");
	fileServer.Replace(":", "_");
	fileServer.Append("\\");

	ABPDownload download;
	download.m_server = server;
	download.m_basePath = appLocal + fileServer;

	// Download only missing file
	for (std::vector<CString>::iterator it = downloadList.begin(); it != downloadList.end(); it++)
	{
		CString final = download.m_basePath + *it;
		final.Replace("/", "\\");
		DWORD exist = GetFileAttributes(final); // Easy way to see if a file exists
		if (exist==INVALID_FILE_ATTRIBUTES)
			download.m_downloadList.push_back(*it);
	}