示例#1
0
        public async static Task SaveOptionsAsync(VersionOption.Type type, List <VersionOption> opts, LaunchHandler core, Modules.MCVersion version)
        {
            await Task.Factory.StartNew(() =>
            {
                try
                {
                    if (version != null && opts != null)
                    {
                        List <string> optLines = new List <string>();
                        foreach (var item in opts)
                        {
                            optLines.Add(item.ToString());
                        }
                        string Path = "";
                        switch (type)
                        {
                        case VersionOption.Type.options:
                            Path = core.GetVersionOptionsPath(version);
                            break;

                        case VersionOption.Type.optionsof:
                            Path = core.GetVersionOptionsofPath(version);
                            break;
                        }
                        File.WriteAllLines(Path, optLines.ToArray());
                    }
                }
                catch (Exception) { }
            });
        }
示例#2
0
        public async static Task <List <VersionOption> > GetOptionsAsync(VersionOption.Type type, LaunchHandler core, Modules.MCVersion version)
        {
            return(await Task.Factory.StartNew(() =>
            {
                if (version != null)
                {
                    try
                    {
                        string Path = "";
                        switch (type)
                        {
                        case VersionOption.Type.options:
                            Path = core.GetVersionOptionsPath(version);
                            break;

                        case VersionOption.Type.optionsof:
                            Path = core.GetVersionOptionsofPath(version);
                            break;

                        default:
                            return null;
                        }

                        if (!File.Exists(Path))
                        {
                            return null;
                        }
                        string[] lines = File.ReadAllLines(Path);
                        List <VersionOption> options = new List <VersionOption>();
                        foreach (var item in lines)
                        {
                            string[] kv = item.Split(':');
                            if (kv.Length < 2)
                            {
                                continue;
                            }
                            if (kv.Length > 2)
                            {
                                string a = kv[1];
                                for (int i = 2; i < kv.Length; i++)
                                {
                                    a += ":" + kv[i];
                                }
                                options.Add(new VersionOption()
                                {
                                    Key = kv[0], Value = a
                                });
                            }
                            else
                            {
                                options.Add(new VersionOption()
                                {
                                    Key = kv[0], Value = kv[1]
                                });
                            }
                        }
                        return options;
                    }
                    catch (Exception)
                    {
                        return null;
                    }
                }
                else
                {
                    return null;
                }
            }));
        }