AcManager.AppArguments.AddFromFile C# (CSharp) Method

AddFromFile() public static method

public static AddFromFile ( string filename ) : void
filename string
return void
        public static void AddFromFile(string filename) {
            if (!File.Exists(filename)) return;

            foreach (var pair in File.ReadAllLines(filename).Where(x => x.StartsWith("--"))
                                     .Select(x => x.Split(new[] { '=' }, 2).Select(y => y.Trim()).ToArray())
                                     .Select(x => new {
                                         Key = ArgStringToFlag(x[0]),
                                         Value = x.Length == 2 ? x[1] : null
                                     })
                                     .Where(x => x.Key != null)) {
                _args[pair.Key.Value] = pair.Value;
            }
        }

Usage Example

Example #1
0
        private static void MainReal(string[] a)
        {
            if (!Debugger.IsAttached)
            {
                SetUnhandledExceptionHandler();
            }

            AppArguments.Initialize(a);
            var data = AppArguments.Get(AppFlag.StorageLocation);

            if (!string.IsNullOrWhiteSpace(data))
            {
                ApplicationDataDirectory = Path.GetFullPath(data);
            }
            else
            {
                var exe = Assembly.GetEntryAssembly().Location;
                ApplicationDataDirectory = Path.GetFileName(exe).IndexOf("local", StringComparison.OrdinalIgnoreCase) != -1
                        ? Path.Combine(Path.GetDirectoryName(exe) ?? Path.GetFullPath("."), "Data")
                        : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "AcTools Content Manager");
            }

            if (AppArguments.GetBool(AppFlag.VisualStyles, true))
            {
                Application.EnableVisualStyles();
            }

            AppArguments.AddFromFile(Path.Combine(ApplicationDataDirectory, "Arguments.txt"));
            RenameContentToData();

#if COSTURA
            CosturaUtility.Initialize();
#else
            var logFilename = AppArguments.GetBool(AppFlag.LogPacked) ? GetLogName("Packed Log") : null;
            AppArguments.Set(AppFlag.DirectAssembliesLoading, ref PackedHelper.OptionDirectLoading);

            var packedHelper = new PackedHelper("AcTools_ContentManager", "References", logFilename);
            packedHelper.PrepareUnmanaged("LevelDB");
            AppDomain.CurrentDomain.AssemblyResolve += packedHelper.Handler;
#endif

            MainInner(a);
        }