コード例 #1
0
ファイル: MainForm.cs プロジェクト: Friendly0Fire/FLINIEditor
        private void view_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex < 0)
            {
                return;
            }

            if (view.Columns[e.ColumnIndex].DataPropertyName == "Location")
            {
                INIBlock b       = blv[e.RowIndex];
                string   command = "\"" + b.Location + "\" -n" + b.Line;

                System.Diagnostics.Process.Start("notepad++", command);
            }
            else
            {
                if (details == null)
                {
                    details = new DetailsForm();
                    details.Show();
                    details.FormClosed += new FormClosedEventHandler(details_FormClosed);
                }
                else
                {
                    details.Focus();
                }

                details.Data = blv[e.RowIndex];
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: Friendly0Fire/FLINIEditor
        void iParser_INIChangedStart(object sender, EventArgs e)
        {
            this.Invoke((MethodInvoker) delegate
            {
                progress.Visible = true;
                if (view.SelectedRows.Count > 0)
                {
                    INIBlock b            = blv[view.SelectedRows[0].Index];
                    preChangeSelectedType = b.Type.ToLower();
                    preChangeSelectedName = b.Name.ToLower();
                }
                else
                {
                    preChangeSelectedName = preChangeSelectedType = "";
                }

                if (details != null)
                {
                    INIBlock b           = details.Data;
                    preChangeDetailsType = b.Type.ToLower();
                    preChangeDetailsName = b.Name.ToLower();
                }
                else
                {
                    preChangeDetailsName = preChangeDetailsType = "";
                }
            });
        }
コード例 #3
0
        private void viewBlocks_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex < 0)
            {
                return;
            }

            this.Data = data.Blocks[e.RowIndex];
        }
コード例 #4
0
ファイル: INI.cs プロジェクト: Friendly0Fire/FLINIEditor
        public static INIParameter Create(string line, INIBlock parent)
        {
            Match  m    = parameter.Match(line);
            string name = m.Groups["name"].Value;

            if (name == "")
            {
                return(null);
            }
            string vals = m.Groups["value"].Value;

            return(new INIParameter(name, vals, parent));
        }
コード例 #5
0
ファイル: INI.cs プロジェクト: Friendly0Fire/FLINIEditor
        private INIParameter(string name, string vals, INIBlock parent)
        {
            this.name   = name.Trim();
            this.parent = parent;

            errors = new List <ValidationError>();

            valid = true;

            string[] valsArray = vals.Split(',');
            values = new INIValue[valsArray.Length];

            for (int a = 0; a < valsArray.Length; a++)
            {
                values[a] = new INIValue(valsArray[a].Trim(), a + 1, this);
            }
        }
コード例 #6
0
        private void AddToRefMap(INIBlock b)
        {
            if (b.Name == "<none>" || b.Name == null)
            {
                return;
            }
            // Add boolean instead?

            string key = b.Type.ToLower() + XMLValue.RefDelimiter + b.Name.ToLower();

            if (!refMap.ContainsKey(key))
            {
                refMap.Add(key, b);
            }
            else if (!b.Partial && !refMap[key].Partial)
            {
                INIBlock b2 = refMap[key];
                if (b.Parent != null || b2.Parent != null && b.Parent != b2.Parent)
                {
                    return;
                }

                bool alreadyAdded = false;
                foreach (ValidationError e in b2.Errors)
                {
                    if (e.Type == ValidationError.XType.CONFLICT_ERROR)
                    {
                        alreadyAdded = true;
                        break;
                    }
                }
                INIValue v1 = b.NameValue;
                INIValue v2 = b2.NameValue;

                v1.Errors.Add(new ValidationError("Block '" + b.Name + "' of type '" + b.Type + "' has a name conflict.", ValidationError.XSeverity.ERROR, ValidationError.XType.CONFLICT_ERROR));
                v1.Revalidate();

                if (!alreadyAdded)
                {
                    v2.Errors.Add(new ValidationError("Block '" + b2.Name + "' of type '" + b2.Type + "' has a name conflict.", ValidationError.XSeverity.ERROR, ValidationError.XType.CONFLICT_ERROR));
                    v2.Revalidate();
                }
            }
        }
コード例 #7
0
        private void ParseFile(string filename)
        {
            if (!File.Exists(filename))
            {
                throw new IOException("File " + filename + " does not exist. Did the filesystem change during parsing?");
            }

            PeekStreamReader sr = new PeekStreamReader(filename);

            while (true)
            {
                INIBlock i = INIBlock.Create(sr, filename);
                if (i != null)
                {
                    blocks.Add(i);
                }
                else
                {
                    break;
                }
            }
            sr.Close();
        }
コード例 #8
0
ファイル: MainForm.cs プロジェクト: Friendly0Fire/FLINIEditor
        private void exportToCSVToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string export;

            if (exportCSVDialog.ShowDialog() == DialogResult.OK)
            {
                export = exportCSVDialog.FileName;
            }
            else
            {
                return;
            }

            System.Collections.IEnumerable bc = (System.Collections.IEnumerable)view.Rows;
            if (view.SelectedRows.Count > 1)
            {
                bc = (System.Collections.IEnumerable)view.SelectedRows;
            }

            string firstType = null;

            // Get all possible parameters

            List <string> columns = new List <string>();

            foreach (DataGridViewRow row in bc)
            {
                INIBlock b = blv[row.Index];
                if (firstType == null)
                {
                    firstType = b.Type;
                }
                else if (b.Type != firstType)
                {
                    MessageBox.Show("Selected rows are of different block types; cannot generate consistent CSV file.", "Mismatched block types!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                foreach (INIParameter p in b.Parameters)
                {
                    if (!columns.Contains(p.Name))
                    {
                        columns.Add(p.Name);
                    }
                }
            }

            // Create the CSV file
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(String.Join(",", columns.ToArray()));

            foreach (DataGridViewRow row in bc)
            {
                INIBlock b = blv[row.Index];

                string[] cols = new string[columns.Count];

                foreach (INIParameter p in b.Parameters)
                {
                    string vals = "";
                    foreach (INIValue v in p)
                    {
                        vals += ", " + v.Value;
                    }
                    int colindex = columns.IndexOf(p.Name);
                    if (cols[colindex] == null)
                    {
                        cols[colindex] = vals.Substring(2);
                    }
                    else
                    {
                        cols[colindex] += Environment.NewLine + vals.Substring(2);
                    }
                }

                for (int a = 0; a < cols.Length; a++)
                {
                    if (cols[a] == null)
                    {
                        cols[a] = " ";
                    }
                    else
                    {
                        cols[a] = "\"" + cols[a] + "\"";
                    }
                }

                sb.AppendLine(String.Join(",", cols));
            }

            File.WriteAllText(export, sb.ToString());
        }
コード例 #9
0
        public void MatchBlocks(XMLParser xParser)
        {
            List <INIBlock> removals = new List <INIBlock>();

            INIBlock current = null;

            foreach (INIBlock b in blocks)
            {
                if (b.Matched)
                {
                    continue;
                }

                foreach (XMLBlock x in xParser.Blocks)
                {
                    if (current != null)
                    {
                        if (!current.MatchNext(b, xParser.Parameters))
                        {
                            current = null;
                        }
                        else
                        {
                            removals.Add(b);
                            AddToRefMap(b);
                        }
                    }
                    if (current == null && b.Match(x, xParser.Parameters))
                    {
                        current = b;
                        AddToRefMap(b);
                    }

                    if (b.Matched)
                    {
                        break;
                    }
                }

                if (!b.Matched)
                {
                    b.MatchAssumptions(xParser.Parameters);
                    AddToRefMap(b);
                }
            }

            for (int a = 0; a < blocks.Count; a++)
            {
                INIBlock b = blocks[a];

                List <INIValue> refs  = b.GetReferenceValues();
                List <INIValue> refs2 = b.GetReference2Values();
                foreach (INIValue v in refs)
                {
                    string[] rs           = v.Xml.RefBlockType.Split(XMLValue.MultiRefDelimiter);
                    bool     hasOneKey    = false;
                    INIBlock matchedBlock = null;
                    foreach (string type in rs)
                    {
                        string key = type + XMLValue.RefDelimiter + v.Value.ToLower();
                        if (refMap.ContainsKey(key))
                        {
                            matchedBlock = refMap[key];

                            b.References.Add(matchedBlock);
                            if (refs2.Contains(v))
                            {
                                b.Referenced.Add(matchedBlock);
                            }
                            matchedBlock.Referenced.Add(b);

                            hasOneKey = true;
                        }
                    }

                    if (!hasOneKey || !matchedBlock.Exists)
                    {
                        v.Errors.Add(new ValidationError("Value " + v.Offset + ", '" + v.Value + "', of parameter '" + v.Parent.Name + "' references to a non-existent entity of type(s) '" + v.Xml.RefBlockType.Replace(",", "' or '") + "'.", ValidationError.XSeverity.ERROR, ValidationError.XType.BAD_REFERENCE_ERROR));
                        v.Revalidate();

                        if (matchedBlock == null)
                        {
                            INIBlock fb = new INIBlock(v.Value);
                            fb.References.Add(b);
                            if (refs2.Contains(v))
                            {
                                b.Referenced.Add(fb);
                            }
                            b.References.Add(fb);

                            blocks.Add(fb);
                        }
                    }
                }

                if (removals.Contains(b))
                {
                    removals.Remove(b);
                    blocks.Remove(b);
                    a--;
                }
            }
        }