Пример #1
0
        public static void ItemGroupCopyEntries(List <ReadableTuple <int> > items, BaseDb gdb, TabControl control, ServerType serverType)
        {
            var parent = WpfUtilities.FindDirectParentControl <SdeEditor>(control);

            parent.AsyncOperation.SetAndRunOperation(new GrfThread(delegate {
                items = items.OrderBy(p => p.GetKey <int>()).ToList();

                StringBuilder builder = new StringBuilder();

                try {
                    AProgress.Init(parent);
                    DbLoaderErrorHandler.Start();

                    var dbItems = gdb.GetMeta <int>(ServerDbs.Items);

                    List <string> aegisNames = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.AegisName.Index)).ToList();
                    List <string> names      = dbItems.FastItems.Select(p => p.GetStringValue(ServerItemAttributes.Name.Index)).ToList();

                    for (int i = 0; i < items.Count; i++)
                    {
                        AProgress.IsCancelling(parent);
                        DbWriterMethods.DbItemGroupWriter2(items[i], serverType, builder, gdb, aegisNames, names);
                        parent.Progress = (i + 1f) / items.Count * 100f;
                    }
                }
                catch (OperationCanceledException) { }
                finally {
                    AProgress.Finalize(parent);
                    DbLoaderErrorHandler.Stop();
                }

                Clipboard.SetText(builder.ToString());
            }, parent, 200, null, true, true));
        }
Пример #2
0
        private void _reloadDatabase(bool alreadyAsync)
        {
            try {
                if (!alreadyAsync)
                {
                    AProgress.Init(this);
                    _mainTabControl.Dispatch(p => p.IsEnabled = false);
                }

                _debugList.Dispatch(p => _debugItems.Clear());
                _debugList.Dispatch(p => ((TabItem)_mainTabControl.Items[1]).Header = new DisplayLabel {
                    DisplayText = "Error console", FontWeight = FontWeights.Bold
                });
                _clientDatabase.Reload(this);
                _delayedReloadDatabase = false;
            }
            catch (OperationCanceledException) {
                _mainTabControl.Dispatch(p => p.SelectedIndex = 0);
                _delayedReloadDatabase = true;
                GrfThread.Start(delegate {
                    Thread.Sleep(300);
                    _mainTabControl.Dispatch(p => Keyboard.Focus(_tviItemDb.TextBoxItem));
                });
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
                _mainTabControl.Dispatch(p => p.SelectedIndex = 0);
                _delayedReloadDatabase = true;
                GrfThread.Start(delegate {
                    Thread.Sleep(300);
                    _mainTabControl.Dispatch(p => Keyboard.Focus(_tviItemDb.TextBoxItem));
                });
            }
            finally {
                if (!alreadyAsync)
                {
                    AProgress.Finalize(this);
                    _mainTabControl.Dispatch(p => p.IsEnabled = true);
                }

                _debugList.Dispatch(delegate {
                    if (_debugItems.Count > 0)
                    {
                        _debugList.Dispatch(p => ((TabItem)_mainTabControl.Items[1]).Header = new DisplayLabel {
                            DisplayText = "Error console *", FontWeight = FontWeights.Bold
                        });
                        _debugList.ScrollIntoView(_debugItems.Last());
                        ((TabItem)_mainTabControl.Items[1]).IsSelected = true;
                    }
                });
            }
        }
Пример #3
0
 private void _startTask(Action action)
 {
     try {
         AProgress.Init(this);
         action();
     }
     catch (OperationCanceledException) {
     }
     catch (Exception err) {
         ErrorHandler.HandleException(err);
     }
     finally {
         AProgress.Finalize(this);
     }
 }
Пример #4
0
        private void _listViewResults_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            var item = _listViewResults.GetObjectAtPoint <ListViewItem>(e.GetPosition(_listViewResults));

            if (item != null)
            {
                HashSet <CmdInfo> commands = new HashSet <CmdInfo>();

                foreach (ValidationErrorView error in _listViewResults.SelectedItems)
                {
                    error.GetCommands(commands);
                }

                ContextMenu menu = new ContextMenu();

                foreach (var cmd in commands)
                {
                    var lcmd = cmd;

                    MenuItem mitem = new MenuItem {
                        Header = cmd.DisplayName, Icon = new Image {
                            Source = ApplicationManager.GetResourceImage(cmd.Icon)
                        }
                    };
                    mitem.Click += delegate {
                        var items = _listViewResults.SelectedItems.Cast <ValidationErrorView>().ToList();

                        _asyncOperation.SetAndRunOperation(new GrfThread(delegate {
                            List <object> dbs = new List <object>();

                            foreach (var serverDb in ServerDbs.ListDbs)
                            {
                                var db = _sdb.TryGetDb(serverDb);

                                if (db != null)
                                {
                                    if (db.AttributeList.PrimaryAttribute.DataType == typeof(int))
                                    {
                                        var adb = (AbstractDb <int>)db;
                                        dbs.Add(adb);
                                    }
                                    else if (db.AttributeList.PrimaryAttribute.DataType == typeof(string))
                                    {
                                        var adb = (AbstractDb <string>)db;
                                        dbs.Add(adb);
                                    }
                                }
                            }

                            foreach (var db in dbs)
                            {
                                _to <int>(db, _onBegin);
                                _to <string>(db, _onBegin);
                            }

                            try {
                                AProgress.Init(_validation);

                                _validation.Grf.Close();
                                _validation.Grf.Open(GrfPath.Combine(SdeAppConfiguration.ProgramDataPath, "missing_resources.grf"), GrfLoadOptions.OpenOrNew);

                                for (int i = 0; i < items.Count; i++)
                                {
                                    AProgress.IsCancelling(_validation);
                                    if (!lcmd.Execute(items[i], items))
                                    {
                                        return;
                                    }
                                    _validation.Progress = (float)i / items.Count * 100f;
                                }

                                if (_validation.Grf.IsModified)
                                {
                                    _validation.Progress = -1;
                                    _validation.Grf.QuickSave();
                                    _validation.Grf.Reload();
                                    _validation.Grf.Compact();
                                }
                            }
                            catch (OperationCanceledException) {
                            }
                            catch (Exception err) {
                                ErrorHandler.HandleException(err);
                            }
                            finally {
                                foreach (var db in dbs)
                                {
                                    _to <int>(db, _onEnd);
                                    _to <string>(db, _onEnd);
                                }

                                _validation.Grf.Close();
                                AProgress.Finalize(_validation);
                            }
                        }, _validation, 200, null, true, true));
                    };

                    menu.Items.Add(mitem);
                }

                item.ContextMenu        = menu;
                item.ContextMenu.IsOpen = true;
            }
            else
            {
                e.Handled = true;
            }
        }
Пример #5
0
        private void _menuItemMerge_Click(object sender, RoutedEventArgs e)
        {
            try {
                if (!_validateState())
                {
                    return;
                }

                string file = PathRequest.OpenFileMapcache("filter", "Grf and Dat Files (*.grf, *.dat)|*.grf;*.dat");

                if (file != null)
                {
                    if (file.IsExtension(".grf"))
                    {
                        _asyncOperation.SetAndRunOperation(new GrfThread(delegate {
                            AProgress.Init(_cache);

                            try {
                                _cache.Commands.Begin();

                                List <FileEntry> files = new List <FileEntry>();
                                int count = 0;

                                using (GrfHolder grf = new GrfHolder(file, GrfLoadOptions.Normal)) {
                                    files.AddRange(grf.FileTable.EntriesInDirectory("data\\", SearchOption.TopDirectoryOnly).Where(entry => entry.RelativePath.IsExtension(".gat")));

                                    foreach (var entry in files)
                                    {
                                        count++;
                                        AProgress.IsCancelling(_cache);
                                        FileEntry rswEntry = grf.FileTable.TryGet(entry.RelativePath.ReplaceExtension(".rsw"));

                                        if (rswEntry == null)
                                        {
                                            continue;
                                        }

                                        _cache.Progress = (float)count / files.Count * 100f;
                                        _cache.Commands.AddMap(Path.GetFileNameWithoutExtension(entry.DisplayRelativePath), entry.GetDecompressedData(), rswEntry.GetDecompressedData());
                                    }
                                }
                            }
                            catch (OperationCanceledException) {
                                _cache.IsCancelled = true;
                                _cache.Commands.CancelEdit();
                            }
                            catch (Exception err) {
                                _cache.Commands.CancelEdit();
                                ErrorHandler.HandleException(err);
                            }
                            finally {
                                _cache.Commands.End();
                                AProgress.Finalize(_cache);
                            }
                        }, _cache, 200));
                    }
                    else if (file.IsExtension(".dat"))
                    {
                        Mapcache cache = new Mapcache(file);

                        try {
                            _cache.Commands.Begin();

                            foreach (var map in cache.Maps)
                            {
                                _cache.Commands.AddMapRaw(map.MapName, map);
                            }
                        }
                        catch {
                            _cache.Commands.CancelEdit();
                            throw;
                        }
                        finally {
                            _cache.Commands.End();
                        }
                    }
                    else
                    {
                        throw new Exception("Unreognized file format.");
                    }
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
        }
Пример #6
0
 private void _dull()
 {
     AProgress.Finalize(_cache);
 }