private void _miLoadLoad_Click(object sender, RoutedEventArgs e)
        {
            try {
                string path = PathRequest.OpenFileCde("filter", "Python Files|*.py");

                if (path != null)
                {
                    var text = File.ReadAllText(path);
                    _textEditor.Document.Replace(0, _textEditor.Document.TextLength, text);
                    _rcm.AddRecentFile(path);
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Esempio n. 2
0
        private void _menuItemProjectLoadAs_Click(object sender, RoutedEventArgs e)
        {
            try {
                string file = PathRequest.OpenFileCde("filter", FileFormat.MergeFilters(Format.Sde));

                if (file != null)
                {
                    if (File.Exists(file))
                    {
                        _recentFilesManager.AddRecentFile(file);
                        ReloadSettings(file);
                    }
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err.Message, ErrorLevel.Warning);
            }
        }
Esempio n. 3
0
        public override void ImportFromFile(string fileDefault = null)
        {
            try {
                string file = fileDefault ?? PathRequest.OpenFileCde("filter", "All db files|*.conf;*.txt");

                if (file == "clipboard")
                {
                    if (!Clipboard.ContainsText())
                    {
                        return;
                    }

                    file = TemporaryFilesManager.GetTemporaryFilePath("clipboard_{0:0000}.txt");
                    File.WriteAllText(file, Clipboard.GetText());
                }

                if (file != null)
                {
                    try {
                        Table.Commands.BeginEdit(new GroupCommand <TKey, TValue>());

                        GenericDatabase gdb = (GenericDatabase)Database;
                        gdb.GetDb <TKey>(Settings.DbData).LoadDb(file);
                    }
                    catch {
                        Table.Commands.CancelEdit();
                    }
                    finally {
                        Table.Commands.EndEdit();
                    }

                    _listView_SelectionChanged(this, null);
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Esempio n. 4
0
        public override void ImportFromFile(string fileDefault = null, bool autoIncrement = false)
        {
            try {
                string file = fileDefault ?? PathRequest.OpenFileCde("filter", "All db files|*.conf;*.txt");

                if (file == "clipboard")
                {
                    if (!Clipboard.ContainsText())
                    {
                        return;
                    }

                    file = TemporaryFilesManager.GetTemporaryFilePath("clipboard_{0:0000}.txt");
                    File.WriteAllText(file, Clipboard.GetText());
                }

                if (file != null)
                {
                    try {
                        Table.Commands.Begin();
                        ProjectDatabase.GetDb <TKey>(Settings.DbData).LoadFromClipboard(file);
                    }
                    catch {
                        Table.Commands.CancelEdit();
                    }
                    finally {
                        Table.Commands.EndEdit();

                        if (autoIncrement && typeof(TKey) == typeof(int))
                        {
                            var cmds = Table.Commands.GetUndoCommands();

                            if (cmds.Count > 0)
                            {
                                var lastCmd = cmds.Last() as GroupCommand <TKey, TValue>;

                                if (lastCmd != null)
                                {
                                    if (lastCmd.Commands.Count > 0 && lastCmd.Commands.OfType <ChangeTupleProperties <TKey, TValue> >().Count() == 1)
                                    {
                                        var firstKey = lastCmd.Commands.First().Key;

                                        var tuple    = new ReadableTuple <TKey>(firstKey, Table.AttributeList);
                                        var oldTuple = (ReadableTuple <TKey>)(object) Table.TryGetTuple(firstKey);
                                        tuple.Copy(oldTuple);
                                        tuple.Added = true;

                                        ProjectDatabase.Commands.Undo();
                                        Table.Commands.AddTuple(tuple.GetKey <TKey>(), (TValue)(object)tuple, false, true, null);
                                    }
                                }
                            }
                        }
                    }

                    _listView_SelectionChanged(this, null);
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Esempio n. 5
0
        private void _menuItemUpdateClientQuests_Click(object sender, RoutedEventArgs e)
        {
            try {
                var tab = FindTopmostTab();

                if (tab == null)
                {
                    return;
                }

                string file = PathRequest.OpenFileCde("fileName", "iRO-questid2display.txt");

                if (file != null)
                {
                    var db    = ProjectDatabase.GetDb <int>(ServerDbs.CQuests);
                    var table = db.Table;

                    try {
                        table.Commands.BeginNoDelay();

                        foreach (string[] elements in TextFileHelper.GetElementsInt(File.ReadAllBytes(file)))
                        {
                            int itemId = Int32.Parse(elements[0]);
                            var tuple  = table.TryGetTuple(itemId);

                            if (tuple != null)
                            {
                                DbIOClientQuests.SetQuestValue(table, tuple, elements, 1);
                                table.Set(itemId, ClientQuestsAttributes.SG, elements[2]);
                                table.Set(itemId, ClientQuestsAttributes.QUE, elements[3]);
                                DbIOClientQuests.SetQuestValue(table, tuple, elements, 4);
                                DbIOClientQuests.SetQuestValue(table, tuple, elements, 5);
                            }
                            else
                            {
                                ReadableTuple <int> newTuple = new ReadableTuple <int>(itemId, ClientQuestsAttributes.AttributeList);
                                table.Commands.AddTuple(itemId, newTuple);
                                table.Commands.Set(newTuple, ClientQuestsAttributes.Name, elements[1]);
                                table.Commands.Set(newTuple, ClientQuestsAttributes.SG, elements[2]);
                                table.Commands.Set(newTuple, ClientQuestsAttributes.QUE, elements[3]);
                                table.Commands.Set(newTuple, ClientQuestsAttributes.FullDesc, elements[4]);
                                table.Commands.Set(newTuple, ClientQuestsAttributes.ShortDesc, elements[5]);
                            }
                        }

                        var db2 = db.ProjectDatabase.GetMetaTable <int>(ServerDbs.Quests);

                        foreach (var quest in db2.FastItems)
                        {
                            var id    = quest.Key;
                            var tuple = table.TryGetTuple(id);

                            if (tuple != null)
                            {
                                DbIOClientQuests.SetQuestValue(table, tuple, quest.GetValue <string>(ServerQuestsAttributes.QuestTitle), ClientQuestsAttributes.Name.Index);
                            }
                            else
                            {
                                ReadableTuple <int> newTuple = new ReadableTuple <int>(id, ClientQuestsAttributes.AttributeList);
                                table.Commands.AddTuple(id, newTuple);
                                table.Commands.Set(newTuple, ClientQuestsAttributes.Name, quest.GetValue <string>(ServerQuestsAttributes.QuestTitle));
                                table.Commands.Set(newTuple, ClientQuestsAttributes.SG, "SG_FEEL");
                                table.Commands.Set(newTuple, ClientQuestsAttributes.QUE, "QUE_NOIMAGE");
                                table.Commands.Set(newTuple, ClientQuestsAttributes.FullDesc, "...");
                                table.Commands.Set(newTuple, ClientQuestsAttributes.ShortDesc, "");
                            }
                        }

                        Debug.Ignore(() => DbDebugHelper.OnLoaded(db.DbSource, db.ProjectDatabase.MetaGrf.FindTkPath(file), db));
                    }
                    catch (Exception err) {
                        table.Commands.CancelEdit();
                        ErrorHandler.HandleException(err);
                    }
                    finally {
                        table.Commands.End();
                    }
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }