Exemple #1
0
        private void WirteModFile(PdxMod pdxMod)
        {
            var filePath = ModGlobalData.MOD_PATH_ROOT + pdxMod.Directory + ".mod";

            File.WriteAllText(filePath, pdxMod.ToString());

            var descriptorMod = pdxMod.Clone();

            descriptorMod.Directory = "";
            var descriptorPath = ModGlobalData.MOD_PATH_ROOT + pdxMod.Directory + @"\descriptor.mod";

            File.WriteAllText(descriptorPath, descriptorMod.ToString());

            ListBoxItem      listBoxItem      = (ListBoxItem)(listView.ItemContainerGenerator.ContainerFromIndex(listView.SelectedIndex));
            ContentPresenter contentPresenter = FindVisualChild <ContentPresenter>(listBoxItem);
            DataTemplate     dataTemplate     = contentPresenter.ContentTemplate;
            Image            target           = (Image)dataTemplate.FindName("listImageView", contentPresenter);

            target.GetBindingExpression(Image.SourceProperty).UpdateTarget();

            if (!Directory.Exists(ModGlobalData.MOD_PATH_ROOT + CurrentMod.Directory))
            {
                Directory.CreateDirectory(ModGlobalData.MOD_PATH_ROOT + CurrentMod.Directory);
            }
            if (!CurrentMod.Picture.Equals("thumbnail.png"))
            {
                File.Copy(CurrentMod.Picture, ModGlobalData.MOD_PATH_ROOT + CurrentMod.Directory + "\\thumbnail.png", true);
            }
        }
Exemple #2
0
        public static void LoadModProjects()
        {
            CreateExampleModProject();

            // 获取所有得 mod 项目文件夹
            DirectoryInfo[] directoryInfos = new DirectoryInfo(ModGlobalData.MOD_PATH_ROOT).GetDirectories();
            foreach (DirectoryInfo directoryInfo in directoryInfos)
            {
                if (File.Exists(directoryInfo.Parent.FullName + @"\" + directoryInfo.Name + ".mod"))
                {
                    // 获取mod配置文件
                    FileInfo      fileInfo      = new FileInfo(directoryInfo.Parent.FullName + @"\" + directoryInfo.Name + ".mod");
                    ModFileParser modFileParser = new ModFileParser();
                    PdxMod        pdxMod        = modFileParser.ParseModFile(fileInfo.FullName);
                    ModProjects.Add(pdxMod);
                }
            }
        }
Exemple #3
0
        private void SaveModFile(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(pathView.Text))
            {
                MessageBox.Show("路径不能为空");
            }
            else if (String.IsNullOrWhiteSpace(versionView.Text))
            {
                MessageBox.Show("Mod版本号不能为空");
            }
            else if (String.IsNullOrWhiteSpace(supportedVersionView.Text))
            {
                MessageBox.Show("群星版本号不能为空");
            }
            else if (String.IsNullOrWhiteSpace(tagsdView.Text))
            {
                MessageBox.Show("标签不能为空");
            }
            else if (String.IsNullOrEmpty(CurrentMod.Picture))
            {
                MessageBox.Show("还未选择封面图", "错误");
            }
            else
            {
                if (!CurrentMod.IsModData)
                {
                    WirteModFile(CurrentMod);
                }
                else
                {
                    var mod = CurrentMod.Clone();
                    mod.IsModData = false;
                    WirteModFile(mod);
                    ModGlobalData.CreateExampleModProject();
                    listView.ItemsSource = null;
                    listView.ItemsSource = ModGlobalData.ModProjects;
                    CurrentMod           = ModGlobalData.ModProjects.First();
                }

                MessageBox.Show("已保存");
            }
        }
        public PdxMod ParseModFile(string filePath)
        {
            PdxMod result = new PdxMod();

            // 如果文件是空得,直接返回空对象
            string context = File.ReadAllText(filePath);

            if ("".Equals(context) || context == String.Empty)
            {
                return(null);
            }

            PdxLexer lexer = new PdxLexer(context);

            for (; ;)
            {
                lexer.SkipWhitespace(); // 跳过注释和空白字符

                char ch = lexer.currentHanlde;
                if (ch == 'n' || ch == 'p' || ch == 'v' || ch == 's' || ch == 't' || ch == 'r')
                {
                    var key = lexer.ParseStringKey();
                    switch (key)
                    {
                    case "name":
                        lexer.SkipEqualSign();
                        result.Name = lexer.ParseStringValueInQuotes();
                        break;

                    case "picture":
                        lexer.SkipEqualSign();
                        result.Picture = lexer.ParseStringValueInQuotes();
                        break;

                    case "version":
                        lexer.SkipEqualSign();
                        result.Version = lexer.ParseStringValueInQuotes();
                        break;

                    case "supported_version":
                        lexer.SkipEqualSign();
                        result.SupportedVersion = lexer.ParseStringValueInQuotes();
                        break;

                    case "path":
                        lexer.SkipEqualSign();
                        result.Path = lexer.ParseStringValueInQuotes();
                        break;

                    case "tags":
                        lexer.SkipEqualSign();
                        LinkedList <String> tags = lexer.ParseStringArrayValue();
                        foreach (PdxModTag t in result.Tags)
                        {
                            foreach (String tag in tags)
                            {
                                if (t.Loclization_English.Equals(tag))
                                {
                                    t.IsChecked = true;
                                }
                            }
                        }
                        break;

                    case "remote_file_id":
                        lexer.SkipEqualSign();
                        result.RemoteFileId = lexer.ParseStringValueInQuotes();
                        break;
                    }
                }
                else if (ch == (char)0)
                {
                    break;
                }
                else
                {
                    lexer.Next();
                }
            }

            return(result);
        }