public static PatchManifest Parse(XmlDocument doc, string baseUrl)
 {
     Uri baseUri = new Uri(baseUrl);
     PatchManifest patchInfo = new PatchManifest();
     XmlNode xmlPatch = doc.SelectSingleNode("patch|dayzrp/patch");
     patchInfo.launcherVersion = xmlPatch.Attribute("launcherVersion", "");
     string launcherUrl = xmlPatch.Attribute("launcherUrl", "");
     patchInfo.mode = xmlPatch.Attribute("mode", "");
     if (!Uri.TryCreate(baseUri, launcherUrl, out patchInfo.launcherUri))
         return null;
     patchInfo.dataDir = xmlPatch.Attribute("data", "");
     XmlNodeList xmlFiles = xmlPatch.SelectNodes("file");
     foreach (XmlNode xmlFile in xmlFiles)
     {
         string path = xmlFile.Attribute("path", "");
         string hash = xmlFile.Attribute("hash", "");
         string defaultUrl = Path.Combine(baseUrl, patchInfo.dataDir + "/" + path);
         string url = xmlFile.Attribute("url", defaultUrl);
         if (String.IsNullOrEmpty(path) || String.IsNullOrEmpty(hash) || String.IsNullOrEmpty(url))
             return null;
         Uri uri;
         if (!Uri.TryCreate(baseUri, url, out uri))
             return null;
         PatchManifest.AssetInfo asset = new PatchManifest.AssetInfo
         {
             uri = uri,
             hash = hash.HexToBytes()
         };
         patchInfo.assets.Add(path.ToLowerInvariant(), asset);
     }
     XmlNode xmlServers = doc.SelectSingleNode("servers|dayzrp/servers");
     if (xmlServers != null)
     {
         patchInfo.servers = new List<ServerInfo>();
         XmlNodeList xmlServerList = xmlServers.SelectNodes("server");
         foreach (XmlNode xmlServer in xmlServerList)
         {
             string host = xmlServer.Attribute("host", "");
             if(String.IsNullOrEmpty(host))
                 continue;
             string name = xmlServer.Attribute("name", host);
             string port = xmlServer.Attribute("port", "2302");
             int intPort = 2302;
             int.TryParse(port, out intPort);
             patchInfo.servers.Add(new ServerInfo
                 {
                     name = name,
                     host = host,
                     port = intPort
                 });
         }
     }
     return patchInfo;
 }
Exemple #2
0
        private void PatchManifestDownloaded(Uri uri, byte[] raw, string error, object userData)
        {
            bool guessValid = false;
            try
            {
                DirectoryInfo dir = new DirectoryInfo(m_installPath_DayZRP);
                guessValid = dir.Exists;
            }
            catch (Exception) { }
            if (error != null)
            {
                Log("Failed contacting patch server: " + error);
                SetIsPatching(false, guessValid);
                RefreshServerList();
                m_tabs.SelectedItem = m_tabLaunch;
                return;
            }
            Debug.Assert(uri == m_manifestUri);
            XmlDocument doc = new XmlDocument();
            MemoryStream stream = new MemoryStream(raw);
            string exText = null;
            try
            {
                doc.Load(stream);
                m_patch = PatchManifest.Parse(doc, m_baseUrl);
            }
            catch (Exception e) { exText = e.ToString(); }
            if (m_patch == null)
            {
                Log("Failed to parse XML document");
                if (exText != null)
                    Log("\t" + exText);
                SetIsPatching(false, guessValid);
                RefreshServerList();
                return;
            }
            else
            {
                Log("Retrieved patch manifest");
                if (!String.IsNullOrEmpty(m_patch.launcherVersion) && m_patch.launcherVersion != LauncherVersion)
                {
                    Log("New version of launcher available: " + m_patch.launcherVersion);
                    MessageBoxResult r = MessageBox.Show("New version of launcher available: " + m_patch.launcherVersion+"\nWould you like to update now?", "Launcher out of date!", MessageBoxButton.YesNo);
                    if (r == MessageBoxResult.Yes)
                    {
                        StartLauncherDownload();
                        return;
                    }
                }
            //	else foreach (var a in m_patch.assets)
            //		Log("\tFile: " + a.Key + ", " + StringExtension.ToHexString(a.Value.hash) + ", " + a.Value.uri.ToString());

                if (m_patch.servers != null && m_patch.servers.Count > 0)
                {
                    Dictionary<string, GameServer> servers = new Dictionary<string, GameServer>();
                    foreach(var server in m_patch.servers)
                        servers.Add(server.name, new GameServer(server.host, server.port));
                    m_servers = servers;
                }
                RefreshServerList();
            }

            if (m_patch.mode != "lzma")
            {
                Log("This launcher version is out of date: Unable to understand the patch format!!!" );
                SetIsPatching(false, guessValid);
                RefreshServerList();
                return;
            }

            try
            {
                DirectoryInfo dir = new DirectoryInfo(m_installPath_DayZRP);
                if (!dir.Exists)
                {
                    dir.Create();
                    Log("Installation directory is not valid");
                    MessageBoxResult r = MessageBox.Show("DayZRP is not currently installed!\nWould you like to use BitTorrent for the initial installation (faster)?", "Couldn't find existing DayZRP installation", MessageBoxButton.YesNo);
                    if (r == MessageBoxResult.Yes)
                    {
                        ProcessOutput.RunSafe("http://www.dayzrp.com/t-dayzrp-mod-download", "", "", null, false, true);
                        SetIsPatching(false, false);
                        return;
                    }
                }
            }
            catch (Exception)
            {
                Log("Installation directory is not valid");
                SetIsPatching(false, false);
                return;
            }

            BeginScan();
        }
Exemple #3
0
        public Window1()
        {
            InitializeComponent();

            m_devOptions.Visibility = Visibility.Hidden;

            m_versionText.Text = m_versionText.Text + " " + App.LauncherVersion;

            m_steamTickBox.IsChecked = Properties.Settings.Default.useSteam;
            m_launchCommands.Text = Properties.Settings.Default.launchArgs;

            m_manualInstallBox.IsChecked = Properties.Settings.Default.manualInstall;
            m_manualA2Dir.Text = Properties.Settings.Default.manualA2Dir;
            m_manualA2OADir.Text = Properties.Settings.Default.manualA2OADir;

            //Default servers to display before the XML file has been downloaded
            m_servers.Add("RP1 : S1", new GameServer("81.170.233.200", 2302));
            m_servers.Add("RP1 : S2", new GameServer("81.170.233.202", 2302));
            m_servers.Add("RP1 : S3", new GameServer("81.170.226.216", 2302));
            m_servers.Add("Event Server", new GameServer("81.170.226.216", 2312));

            List<ServerListItem> initialServerList = new List<ServerListItem>();
            foreach (var server in m_servers)
            {
                initialServerList.Add(new ServerListItem()
                {
                    locked = true,
                    online = true,
                    Name = server.Key,
                    Players = "? / ?",
                    PlayerList = "Refreshing..."
                });
            }
            m_serverListBox.ItemsSource = initialServerList;
            if (Properties.Settings.Default.lastServerIdx >= 0 && Properties.Settings.Default.lastServerIdx < initialServerList.Count)
                m_serverListBox.SelectedIndex = Properties.Settings.Default.lastServerIdx;

            m_installPath_Arma2 = ReadRegString("Bohemia Interactive Studio\\ArmA 2", "MAIN");
            m_installPath_Arma2OA = ReadRegString("Bohemia Interactive Studio\\ArmA 2 OA", "MAIN");
            if (String.IsNullOrEmpty(m_installPath_Arma2))
                m_installPath_Arma2 = ReadRegString("Bohemia Interactive Studio\\ArmA 2 Free", "MAIN");
            if (String.IsNullOrEmpty(m_installPath_Arma2) && Properties.Settings.Default.manualInstall)
                m_installPath_Arma2 = Properties.Settings.Default.manualA2Dir;
            if (String.IsNullOrEmpty(m_installPath_Arma2OA) && Properties.Settings.Default.manualInstall)
                m_installPath_Arma2OA = Properties.Settings.Default.manualA2OADir;
            while (String.IsNullOrEmpty(m_installPath_Arma2))
            {
                MessageBoxResult r = MessageBox.Show("Could not locate Arma 2 installation.\n Would you like to manually locate the installation?", "Arma 2 not installed correctly!", MessageBoxButton.OKCancel);
                if (r == MessageBoxResult.OK)
                {
                    Forms.OpenFileDialog fileBrowser = new Forms.OpenFileDialog();
                    fileBrowser.CheckFileExists = true;
                    fileBrowser.CheckPathExists = true;
                    fileBrowser.ReadOnlyChecked = true;
                    fileBrowser.Title = "Please locate Arma2.exe";
                    fileBrowser.FileName = "Arma2.exe";
                    fileBrowser.Filter = "Executable files (*.exe)|*.exe|All files (*.*)|*.*";
                    fileBrowser.RestoreDirectory = true;
                    if (fileBrowser.ShowDialog() == Forms.DialogResult.OK)
                    {
                        m_installPath_Arma2 = Path.GetDirectoryName(fileBrowser.FileName);
                        m_manualA2Dir.Text = m_installPath_Arma2;
                        Properties.Settings.Default.manualA2Dir = m_installPath_Arma2;
                        m_manualInstallBox.IsChecked = true;
                    }
                }
                else
                {
                    Application.Current.Shutdown();
                    return;
                }
            }
            while (String.IsNullOrEmpty(m_installPath_Arma2OA))
            {
                MessageBoxResult r = MessageBox.Show("Could not locate Arma 2 Operation Arrowhead installation.\n Would you like to manually locate the installation?", "Arma 2 OA not installed correctly!", MessageBoxButton.OKCancel);
                if (r == MessageBoxResult.OK)
                {
                    Forms.OpenFileDialog fileBrowser = new Forms.OpenFileDialog();
                    fileBrowser.CheckFileExists = true;
                    fileBrowser.CheckPathExists = true;
                    fileBrowser.ReadOnlyChecked = true;
                    fileBrowser.Title = "Please locate Arma2OA.exe";
                    fileBrowser.FileName = "Arma2OA.exe";
                    fileBrowser.Filter = "Executable files (*.exe)|*.exe|All files (*.*)|*.*";
                    fileBrowser.RestoreDirectory = true;
                    if (fileBrowser.ShowDialog() == Forms.DialogResult.OK)
                    {
                        m_installPath_Arma2OA = Path.GetDirectoryName(fileBrowser.FileName);
                        m_manualA2OADir.Text = m_installPath_Arma2OA;
                        Properties.Settings.Default.manualA2OADir = m_installPath_Arma2OA;
                        m_manualInstallBox.IsChecked = true;
                    }
                }
                else
                {
                    Application.Current.Shutdown();
                    return;
                }
            }
            m_installPath_DayZRP = Path.Combine(m_installPath_Arma2OA, "./@DayZRP");

            m_baseUrl = "http://launcher.dayzrp.com/";
            //	m_baseUrl = "http://localhost/test/";
            m_manifestUri = new Uri(Path.Combine(m_baseUrl, ManifestName));
            m_patch = null;
            m_patchServerBox.Text = m_baseUrl;
            Begin();
        }