예제 #1
0
        private IniObject ReadFile(IniObject iniFile)
        {
            string regexString = @"[0-9]+=[a-zA-Z0-9\/\\]+.(dds|c3)";

            using (FileStream fs = File.Open(iniFile.name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (BufferedStream bs = new BufferedStream(fs))
                    using (StreamReader sr = new StreamReader(bs))
                    {
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            if (Regex.IsMatch(line, regexString, RegexOptions.IgnoreCase))
                            {
                                string[] part = line.Split('=');
                                if (part.Length != 2)
                                {
                                    WriteLog("[Error] ", Color.Red);
                                    WriteLineLog(String.Format("[File: {0}][Data: {1}] - Line does not contain 2 parts", iniFile.name, line));
                                }
                                else
                                {
                                    GraphicObject graphic = new GraphicObject(part[0].ToString(), part[1].ToString());
                                    if (line.EndsWith("dds") || line.EndsWith("DDS"))
                                    {
                                        graphic.type = FileType.DDS;
                                    }
                                    else if (line.EndsWith("c3") || line.EndsWith("C3"))
                                    {
                                        graphic.type = FileType.C3;
                                    }
                                    else
                                    {
                                        graphic.type = FileType.OTHER;
                                    }

                                    if (iniFile.lsGraphic.ContainsKey(graphic.id))
                                    {
                                        string tmpId  = graphic.id;
                                        int    number = 1;
                                        while (iniFile.lsGraphic.ContainsKey(tmpId))
                                        {
                                            tmpId = graphic.id + "_" + (number++);
                                        }
                                        iniFile.lsGraphic.Add(tmpId, graphic);
                                    }
                                    else
                                    {
                                        iniFile.lsGraphic.Add(graphic.id, graphic);
                                    }
                                }
                            }
                            else
                            {
                                //WriteLog("[Warning] ", Color.Orange);
                                //WriteLineLog(String.Format("[File: {0}][Data: {1}] - Line format not valid.", iniFile.name, line));
                            }
                        }
                        return(iniFile);
                    }
        }
예제 #2
0
        private void bw_DoWork(object sender, DoWorkEventArgs e)
        {
            if (Directory.Exists(txtIni.Text))
            {
                string[]         files = Directory.GetFiles(txtIni.Text);
                List <IniObject> lsIni = new List <IniObject>();

                foreach (String file in files)
                {
                    SetStatus("Reading file: " + file);
                    if (!file.ToLower().EndsWith("ini") && !file.ToLower().EndsWith("ani"))
                    {
                        continue;
                    }

                    IniObject ini = new IniObject(file);
                    ini = ReadFile(ini);
                    if (ini.count > 0)
                    {
                        lsIni.Add(ini);
                    }
                    else
                    {
                        WriteLog("[Warning] ", Color.Orange);
                        WriteLineLog(String.Format("[File: {0}] - Does not have valid data.", file));
                    }
                }

                if (lsIni.Count > 0)
                {
                    ExportFile(lsIni);
                }
                else
                {
                    WriteLog("[Warning] ", Color.Orange);
                    WriteLineLog("Does not have ini file to export");
                }
            }
            else
            {
                WriteLog("[Error] ", Color.Red);
                WriteLineLog("Ini folder is not exists.");
                SetStatus("Complete!");
            }
        }
예제 #3
0
        private void Worker_DoWork(object sender, DoWorkEventArgs e)
        {
            string        source = txtSourceFile.Text;
            string        target = txtTargetFile.Text;
            StringBuilder log    = new StringBuilder();

            if (!source.EndsWith("ini") || !target.EndsWith("ini"))
            {
                MessageBox.Show("File's format is invalid");
                return;
            }

            IniObject sourceIni = new IniObject(source);
            IniObject targetIni = new IniObject(target);

            sourceIni = ReadFile(sourceIni);
            targetIni = ReadFile(targetIni);
            IniObject tmp = new IniObject();

            tmp.name      = sourceIni.name;
            tmp.lsGraphic = new Dictionary <string, GraphicObject>(sourceIni.lsGraphic);

            foreach (KeyValuePair <String, GraphicObject> data in tmp.lsGraphic)
            {
                if (targetIni.lsGraphic.ContainsKey(data.Key))
                {
                    sourceIni.lsGraphic[data.Key] = targetIni.lsGraphic[data.Key];
                    log.AppendLine("Found - " + data.Key);
                }
            }

            List <IniObject> lsIni = new List <IniObject>();

            lsIni.Add(sourceIni);
            ExportFile(lsIni);
            WriteLineLog(log.ToString());

            MessageBox.Show("Done !");
        }