Inheritance: System.IO.StreamReader
Esempio n. 1
0
 private static KeyValue GetAppManifestValue(string manifestPath, string key)
 {
     var acfKeys = new KeyValue();
     var reader = new StreamReader(manifestPath);
     var acfReader = new KVTextReader(acfKeys, reader.BaseStream);
     reader.Close();
     return acfKeys.Children.FirstOrDefault(k => k.Name == key);
 }
Esempio n. 2
0
        /// <summary>
        /// Populate this instance from the given <see cref="Stream"/> as a text <see cref="KeyValue"/>.
        /// </summary>
        /// <param name="input">The input <see cref="Stream"/> to read from.</param>
        /// <returns><c>true</c> if the read was successful; otherwise, <c>false</c>.</returns>
        public bool ReadAsText(Stream input)
        {
            this.Children = new List <KeyValue>();

            KVTextReader kvr = new KVTextReader(this, input);

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Populate this instance from the given <see cref="Stream"/> as a text <see cref="KeyValue"/>.
        /// </summary>
        /// <param name="input">The input <see cref="Stream"/> to read from.</param>
        /// <returns><c>true</c> if the read was successful; otherwise, <c>false</c>.</returns>
        public bool ReadAsText(Stream input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input));
            }

            this.Children = new List <KeyValue>();

            using var _ = new KVTextReader(this, input);

            return(true);
        }
Esempio n. 4
0
        internal void RecursiveLoadFromBuffer(KVTextReader kvr)
        {
            bool wasQuoted;
            bool wasConditional;

            while (true)
            {
                // bool bAccepted = true;

                // get the key name
                var name = kvr.ReadToken(out wasQuoted, out wasConditional);

                if (name is null || name.Length == 0)
                {
                    throw new InvalidDataException("RecursiveLoadFromBuffer: got EOF or empty keyname");
                }

                if (name.StartsWith("}") && !wasQuoted)         // top level closed, stop reading
                {
                    break;
                }

                KeyValue dat = new KeyValue(name);
                dat.Children = new List <KeyValue>();
                this.Children.Add(dat);

                // get the value
                string?value = kvr.ReadToken(out wasQuoted, out wasConditional);

                if (wasConditional && value != null)
                {
                    // bAccepted = ( value == "[$WIN32]" );
                    value = kvr.ReadToken(out wasQuoted, out wasConditional);
                }

                if (value == null)
                {
                    throw new Exception("RecursiveLoadFromBuffer:  got NULL key");
                }

                if (value.StartsWith("}") && !wasQuoted)
                {
                    throw new Exception("RecursiveLoadFromBuffer:  got } in key");
                }

                if (value.StartsWith("{") && !wasQuoted)
                {
                    dat.RecursiveLoadFromBuffer(kvr);
                }
                else
                {
                    if (wasConditional)
                    {
                        throw new Exception("RecursiveLoadFromBuffer:  got conditional between key and value");
                    }

                    dat.Value = value;
                    // blahconditionalsdontcare
                }
            }
        }
Esempio n. 5
0
        internal void RecursiveLoadFromBuffer( KVTextReader kvr )
        {
            bool wasQuoted;
            bool wasConditional;

            while ( true )
            {
                bool bAccepted = true;

                // get the key name
                string name = kvr.ReadToken( out wasQuoted, out wasConditional );

                if ( string.IsNullOrEmpty( name ) )
                {
                    throw new Exception( "RecursiveLoadFromBuffer: got EOF or empty keyname" );
                }

                if ( name.StartsWith( "}" ) && !wasQuoted )	// top level closed, stop reading
                    break;

                KeyValue dat = new KeyValue( name );
                dat.Children = new List<KeyValue>();
                this.Children.Add( dat );

                // get the value
                string value = kvr.ReadToken( out wasQuoted, out wasConditional );

                if ( wasConditional && value != null )
                {
                    bAccepted = ( value == "[$WIN32]" );
                    value = kvr.ReadToken( out wasQuoted, out wasConditional );
                }

                if ( value == null )
                    throw new Exception( "RecursiveLoadFromBuffer:  got NULL key" );

                if ( value.StartsWith( "}" ) && !wasQuoted )
                    throw new Exception( "RecursiveLoadFromBuffer:  got } in key" );

                if ( value.StartsWith( "{" ) && !wasQuoted )
                {
                    dat.RecursiveLoadFromBuffer( kvr );
                }
                else
                {
                    if ( wasConditional )
                    {
                        throw new Exception( "RecursiveLoadFromBuffer:  got conditional between key and value" );
                    }

                    dat.Value = value;
                    // blahconditionalsdontcare
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Populate this instance from the given <see cref="Stream"/> as a text <see cref="KeyValue"/>.
        /// </summary>
        /// <param name="input">The input <see cref="Stream"/> to read from.</param>
        /// <returns><c>true</c> if the read was successful; otherwise, <c>false</c>.</returns>
        public bool ReadAsText( Stream input )
        {
            this.Children = new List<KeyValue>();

            KVTextReader kvr = new KVTextReader( this, input );

            return true;
        }
Esempio n. 7
0
        public void DownloadAndInstall(int revision, HashWebClient.RemoteFileInfo archiveInfo, bool steamBeta,
			string steamBuild, UpdatesView view)
        {
            if (steamBeta)
            {
                const int appId = 33930;
                string gameName = "Arma 2: Operation Arrowhead Beta";
                DirectoryInfo armaPath = null;

                try
                {
                    armaPath = new DirectoryInfo(CalculatedGameSettings.Current.Arma2OAPath);
                }
                catch (ArgumentException aex)
                {
                    bool overridenPath = string.IsNullOrWhiteSpace(UserSettings.Current.GameOptions.Arma2OADirectoryOverride);

                    Execute.OnUiThreadSync(() =>
                    {
                        var popup = new InfoPopup("Invalid path", MainWindow.GetWindow(view));
                        popup.Headline.Content = "Game could not be found";
                        popup.SetMessage(overridenPath
                            ? "Invalid game override path, please enter a new game path or remove it"
                            : "Game could not located via the registry, please enter an override path");

                        popup.Show();
                    }, null, DispatcherPriority.Input);

                    return;
                }

                for (armaPath = armaPath.Parent; armaPath != null; armaPath = armaPath.Parent)
                {
                    if (armaPath.Name.Equals("steamapps", StringComparison.OrdinalIgnoreCase))
                    {
                        string manifestName = "appmanifest_" + appId.ToString() + ".acf";
                        string fullManifestPath = Path.Combine(armaPath.FullName, manifestName);
                        if (File.Exists(fullManifestPath))
                        {
                            // Kill Steam so we can edit the game configuration.
                            Process[] processes = Process.GetProcessesByName("Steam");

                            foreach (Process process in processes)
                            {
                                // #YOLO
                                try
                                {
                                    process.Kill();
                                    process.WaitForExit();
                                }
                                catch
                                {
                                    MessageBox.Show("Unable to shut down steam to start patching.",
                                        "Patch error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                                    return;
                                }
                            }

                            var acfKeys = new KeyValue();
                            var reader = new StreamReader(fullManifestPath);
                            var acfReader = new KVTextReader(acfKeys, reader.BaseStream);
                            reader.Close();
                            KeyValue currentBuild = acfKeys.Children.FirstOrDefault(k => k.Name == "buildid");
                            if (!String.IsNullOrEmpty(currentBuild.Value))
                            {
                                if (Equals(currentBuild.Value, steamBuild))
                                {
                                    Execute.OnUiThreadSync(() =>
                                    {
                                        var popup = new InfoPopup("User intervention required", MainWindow.GetWindow(view));
                                        popup.Headline.Content = "Game update using Steam";
                                        popup.SetMessage(gameName + " might be corrupted.\n" +
                                                         "Please validate your client files manually.\n" +
                                                         "Or by clicking on the following link:");
                                        popup.SetLink("steam://validate/" + appId.ToString() + "/", "Update " + gameName);
                                        popup.Closed += (sender, args) => view.CheckForUpdates();
                                        popup.Show();
                                    }, null, DispatcherPriority.Input);
                                }
                                else
                                {
                                    KeyValue gameState = acfKeys.Children.FirstOrDefault(k => k.Name == "StateFlags");
                                    if (!String.IsNullOrEmpty(gameState.Value))
                                    {
                                        currentBuild.Value = steamBuild;
                                        gameState.Value = "2";
                                        acfKeys.SaveToFile(fullManifestPath, false);

                                        Thread.Sleep(1000);

                                        Execute.OnUiThreadSync(() =>
                                        {
                                            var popup = new InfoPopup("User intervention required", MainWindow.GetWindow(view));
                                            popup.Headline.Content = "Game update using Steam";
                                            popup.SetMessage(gameName + " branch switched to BETA.\n" +
                                                             "Please restart Steam to download update.");
                                            popup.Closed += (sender, args) => view.CheckForUpdates();
                                            popup.Show();
                                        }, null, DispatcherPriority.Input);
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("Patching failed, '" + gameName + "' is not located inside a SteamLibrary folder.",
                                    "Patch error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                                return;
                            }

                            return;
                        }
                        else
                        {
                            Execute.OnUiThreadSync(() =>
                            {
                                var popup = new InfoPopup("User intervention required", MainWindow.GetWindow(view));
                                popup.Headline.Content = "Game update using Steam";
                                popup.SetMessage(gameName + " is not installed.\n" +
                                                 "Please install it from the Library tab.\n" +
                                                 "Or by clicking on the following link:");
                                popup.SetLink("steam://install/" + appId.ToString() + "/", "Install " + gameName);
                                popup.Closed += (sender, args) => view.CheckForUpdates();
                                popup.Show();
                            }, null, DispatcherPriority.Input);

                            return;
                        }
                    }
                }
                if (armaPath == null)
                {
                    MessageBox.Show("Patching failed, '" + gameName + "' is not located inside a SteamLibrary folder.",
                        "Patch error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    return;
                }
            }
            else
            {
                DownloadAndInstall(revision, archiveInfo);
            }
        }