Пример #1
0
        private void listMods_DoubleClick(object sender, EventArgs e)
        {
            ListBox list = sender as ListBox;

            if (list.SelectedIndex >= 0)
            {
                ModFile mod = list.Items[list.SelectedIndex] as ModFile;
                ExplorerFile(mod.FileName);
            }
        }
Пример #2
0
        private void listWorkShop_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index >= 0)
            {
                e.DrawBackground();

                ModFile file = (sender as ListBox).Items[e.Index] as ModFile;

                Brush mybsh = Brushes.Black;
                // 焦点框
                e.DrawFocusRectangle();
                if (file.ConflictTable)
                {
                    mybsh = Brushes.Red;
                }
                else if (file.ConflictField)
                {
                    mybsh = Brushes.Orange;
                }

                //文本
                e.Graphics.DrawString((file.WorkshopInfo.Active ? "" : "(未激活)") + file.WorkshopInfo.Name, e.Font, mybsh, e.Bounds, StringFormat.GenericDefault);
            }
        }
Пример #3
0
        private void listMods_SelectedIndexChanged(object sender, EventArgs e)
        {
            listTables.Items.Clear();
            ListBox list = sender as ListBox;

            if (list.SelectedIndex >= 0)
            {
                ModFile mod = list.Items[list.SelectedIndex] as ModFile;

                listTables.Items.Add("文件:   " + mod.FileName);
                listTables.Items.Add("");

                //展示所有冲突的目录
                fileTables[mod.FileName].ForEach(table =>
                {
                    bool conf = false;

                    bool withTag = false;

                    List <string> allFiles = tableFile[table];
                    allFiles = allFiles.Where(p => p != mod.FileName).ToList();
                    if (allFiles.Count > 0)
                    {
                        listTables.Items.Add("目录:   " + table);
                        withTag = true;

                        allFiles.ForEach(o =>
                        {
                            ConflictInfo c = new ConflictInfo();
                            c.File         = mod.FileName;
                            c.Table        = table;
                            c.ConflictType = ConflictType.TABLE;
                            c.ConflictFile = o;
                            listTables.Items.Add(c);
                        });
                        conf = true;
                    }
                    //查看词条冲突情况
                    var tpeName = DBFile.Typename(table);
                    fileFields[mod.FileName].Where(p => p.TableName == tpeName).ToList().ForEach(p =>
                    {
                        List <string> files = fieldFiles[p.TableName + "." + string.Join(".", p.FieldKeyValue)]
                                              .Where(q => q != mod.FileName).ToList();
                        if (files.Count > 0)
                        {
                            if (!withTag)
                            {
                                listTables.Items.Add("目录:   " + table);
                                withTag = true;
                            }
                            files.ForEach(q =>
                            {
                                ConflictInfo c = new ConflictInfo();
                                c.File         = mod.FileName;
                                c.Table        = table;
                                c.ConflictType = ConflictType.KEY;
                                c.ConflictFile = q;
                                c.FieldValue   = p.FieldKeyValue;
                                c.FieldName    = p.FieldKeyName;
                                listTables.Items.Add(c);
                            });
                            conf = true;
                        }
                    });
                    if (!conf && !tsmiHideNormal.Checked)
                    {
                        if (!withTag)
                        {
                            listTables.Items.Add("目录:   " + table);
                            withTag = true;
                        }

                        ConflictInfo con = new ConflictInfo();
                        con.File         = mod.FileName;
                        con.Table        = table;
                        con.ConflictType = ConflictType.NONE;
                        listTables.Items.Add(con);
                    }

                    if (withTag)
                    {
                        listTables.Items.Add("");
                    }
                });
            }
        }
Пример #4
0
        private void loadDir()
        {
            lock (this)
            {
                tableFile.Clear();
                fileTables.Clear();
                listMods.Items.Clear();
                listWorkShop.Items.Clear();
                listTables.Items.Clear();
                fileFields.Clear();
                fieldFiles.Clear();

                if (currentDir == null || currentDir.Length == 0 || !Directory.Exists(currentDir))
                {
                    return;
                }

                //读取所有pack文件
                List <FileInfo> files = new DirectoryInfo(currentDir).GetFiles("*.pack").ToList();

                List <WorkshopInfo> workShopInfos = new List <WorkshopInfo>();

                //加载创意工坊配置
                if (workShopConfigFile != null && workShopConfigFile.Length > 0 && File.Exists(workShopConfigFile))
                {
                    try
                    {
                        using (StreamReader sr = new StreamReader(workShopConfigFile))
                        {
                            workShopInfos = JsonConvert.DeserializeObject <List <WorkshopInfo> >(sr.ReadToEnd());
                        }
                    }
                    catch
                    {
                    }
                }

                //加载创意工坊pack文件
                if (workshopDir != null && workshopDir.Length > 0)
                {
                    string tmp = workshopDir + @"\workshop\content\779340";
                    if (Directory.Exists(tmp))
                    {
                        foreach (DirectoryInfo dir in new DirectoryInfo(tmp).GetDirectories())
                        {
                            files.AddRange(dir.GetFiles("*.pack").ToList());;
                        }
                    }
                }

                //文件排除列表
                List <string> exp = new List <string>();

                //读取manifest.txt文件筛选系统mod
                string[] mainfests = Directory.GetFiles(currentDir, "manifest.txt");
                if (mainfests.Length > 0)
                {
                    using (StreamReader sr = new StreamReader(mainfests[0]))
                    {
                        string line = null;
                        while ((line = sr.ReadLine()) != null)
                        {
                            int idx = line.ToLower().IndexOf(".pack");
                            if (idx > 0)
                            {
                                exp.Add(line.Substring(0, idx + 5));
                            }
                        }
                    }
                }

                files = files.Where(p => !exp.Contains(p.Name)).OrderBy(p => p.Name).ToList();
                files.ForEach(file =>
                {
                    WorkshopInfo wk = null;
                    try
                    {
                        wk = workShopInfos.Find(p => pathEquals(p.Packfile, file.FullName));
                    }
                    catch (Exception e)
                    {
                    }

                    if (wk == null || wk.Active || !tsmiIgnoreUnActive.Checked)
                    {
                        List <PackedFile> packageFile = ReadPackageFile(file.FullName);
                        //填充文件-目录数据
                        fileTables.Add(file.FullName, packageFile.Select(pkg => pkg.FullPath).ToList());
                        fileFields[file.FullName] = new List <ModLine>();


                        packageFile.ForEach(p =>
                        {
                            //填充目录-文件数据
                            if (!tableFile.ContainsKey(p.FullPath))
                            {
                                tableFile[p.FullPath] = new List <string>();
                            }

                            List <string> list = tableFile[p.FullPath];
                            list.Add(file.FullName);

                            if (tsmiCheckLine.Checked)
                            {
                                //填充文件-词条数据
                                List <ModLine> lines = ReadPackedField(p, file.FullName);

                                List <ModLine> fields = fileFields[file.FullName];
                                fields.AddRange(lines);

                                //填充词条-文件数据
                                lines.ForEach(line =>
                                {
                                    string key = line.TableName + "." + string.Join(".", line.FieldKeyValue);
                                    if (!fieldFiles.ContainsKey(key))
                                    {
                                        fieldFiles[key] = new List <string>();
                                    }
                                    List <string> fs = fieldFiles[key];
                                    fs.Add(file.FullName);
                                });
                            }
                        });
                    }
                    else
                    {
                        //填充文件-目录数据
                        fileTables.Add(file.FullName, new List <string>());
                        fileFields[file.FullName] = new List <ModLine>();
                    }
                });

                //填充左侧Mod目录
                foreach (FileInfo file in files)
                {
                    ModFile mod = new ModFile();
                    mod.FileName = file.FullName;
                    mod.Name     = Path.GetFileNameWithoutExtension(file.FullName);

                    //判断是否为创意工坊
                    mod.WorkshopInfo = workShopInfos.Find(p => pathEquals(p.Packfile, file.FullName));

                    if (mod.WorkshopInfo == null || mod.WorkshopInfo.Active || !tsmiIgnoreUnActive.Checked)
                    {
                        //判断是否冲突
                        foreach (string table in fileTables[file.FullName])
                        {
                            if (tableFile[table].Count(p => p != file.FullName) > 0)
                            {
                                mod.ConflictTable = true;
                                break;
                            }
                        }
                        if (tsmiCheckLine.Checked)
                        {
                            //如果目录无冲突,则判断词条冲突情况
                            List <ModLine> lines = fileFields[mod.FileName];
                            foreach (ModLine l in lines)
                            {
                                if (fieldFiles[l.TableName + "." + string.Join(".", l.FieldKeyValue)].Count(p => p != file.FullName) > 0)
                                {
                                    mod.ConflictField = true;
                                    break;
                                }
                            }
                        }
                    }


                    if (mod.WorkshopInfo != null)
                    {
                        listWorkShop.Items.Add(mod);
                    }
                    else
                    {
                        listMods.Items.Add(mod);
                    }
                }

                watcher.Path = currentDir;
                watcher.EnableRaisingEvents = true;

                if (workshopDir != null && workshopDir.Length > 0)
                {
                    string tmp = workshopDir + @"\workshop\content\779340";
                    if (Directory.Exists(tmp))
                    {
                        workshopWatcher.Path = tmp;
                        workshopWatcher.EnableRaisingEvents = true;
                    }
                }

                if (Directory.Exists(launchDir))
                {
                    workshopConfigWatcher.Path = launchDir;
                    workshopConfigWatcher.EnableRaisingEvents = true;
                }
            }
        }