Пример #1
0
 private void SaveCurrentProject(bool isDefaultPosition = true)
 {
     if (CurrentProject == null)
     {
         return;
     }
     SaveCurrentTasks();
     if (CurrentProject.Tasks.Any() == false &&
         MessageBox.Show(GlobalHelper.Get("key_316"), GlobalHelper.Get("key_151"), MessageBoxButton.OKCancel) ==
         MessageBoxResult.Cancel)
     {
         return;
     }
     if (isDefaultPosition)
     {
         ControlExtended.SafeInvoke(() => CurrentProject.Save(dataManager.DataCollections), LogType.Important,
                                    GlobalHelper.Get("key_317"));
         var pro = ConfigFile.GetConfig <DataMiningConfig>().Projects.FirstOrDefault();
         if (pro != null)
         {
             pro.SavePath = CurrentProject.SavePath;
         }
     }
     else
     {
         CurrentProject.SavePath = null;
         ControlExtended.SafeInvoke(() => CurrentProject.Save(dataManager.DataCollections), LogType.Important,
                                    GlobalHelper.Get("key_318"));
     }
     ConfigFile.Config.SaveConfig();
 }
Пример #2
0
        private void unloadedassemblymenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem.Name == "addtoproject")
            {
                NodeAssemblyData data = (NodeAssemblyData)objectview.SelectedNode.Tag;
                CurrentProject.AddManifest(data.AssemblyName);
                CurrentProject.Save(CurrentProjectFilename);
                data.Included   = true;
                data.Loaded     = true;
                data.Definition = LoadAssembly(data.AssemblyName);
                objectview.SelectedNode.ImageKey         = "accept.png";
                objectview.SelectedNode.SelectedImageKey = "accept.png";
                objectview.SelectedNode.Nodes.Clear();

                string realfilename = Path.Combine(CurrentProject.TargetDirectory, data.AssemblyName + ".dll");
                string origfilename = Path.Combine(CurrentProject.TargetDirectory, data.AssemblyName + "_Original.dll");
                if (!File.Exists(origfilename))
                {
                    CreateOriginal(realfilename, origfilename);
                }

                // Populate
                PopulateAssemblyNode(objectview.SelectedNode, data.Definition);
            }
        }
Пример #3
0
 public void SaveCurrentTasks()
 {
     foreach (var process in CurrentProcessCollections)
     {
         SaveTask(process, false);
     }
     CurrentProject.Save();
 }
Пример #4
0
        private void AutosaveTimer_Tick(object sender, EventArgs e)
        {
            AutosaveTimer.Stop();
            if (CurrentProject.file.Length > 0)
            {
                CurrentProject.Save();
            }

            AutosaveTimer.Start();
        }
Пример #5
0
 public override bool Save()
 {
     try
     {
         CurrentProject.Save();
         UnsavedChanges = false;
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #6
0
        /// <summary>
        /// Updates the UI for a hook
        /// </summary>
        /// <param name="hook"></param>
        public void UpdateHook(Hook hook)
        {
            foreach (TabPage tabpage in tabview.TabPages)
            {
                if (tabpage.Tag is HookViewControl && (tabpage.Tag as HookViewControl).Hook == hook)
                {
                    tabpage.Text = hook.Name;
                }
            }

            CurrentProject.Save(CurrentProjectFilename);

            TreeNode hooks = null;

            foreach (var node in objectview.Nodes)
            {
                if ((node as TreeNode).Text == "Hooks")
                {
                    hooks = node as TreeNode;
                    break;
                }
            }
            if (hooks == null)
            {
                return;
            }

            foreach (var node in hooks.Nodes)
            {
                if ((node as TreeNode).Tag == hook)
                {
                    TreeNode treenode = node as TreeNode;

                    treenode.Text = hook.Name;
                    if (hook.Flagged)
                    {
                        treenode.ImageKey         = "script_error.png";
                        treenode.SelectedImageKey = "script_error.png";
                    }
                    else
                    {
                        treenode.ImageKey         = "script_lightning.png";
                        treenode.SelectedImageKey = "script_lightning.png";
                    }


                    break;
                }
            }
        }
        private void AutosaveTimer_Tick(object sender, EventArgs e)
        {
            AutosaveTimer.Stop();
            if (string.IsNullOrEmpty(CurrentProject.file))
            {
                var old = CurrentProject.file;
                CurrentProject.file = Path.Combine(AppConfig.ExeDirectory, "autosave.npcproj");
                CurrentProject.Save();
                CurrentProject.file = old;
            }
            else
            {
                CurrentProject.Save();
            }

            AutosaveTimer.Start();
        }
Пример #8
0
        private void SaveCurrentProject(bool isDefaultPosition = true)
        {
            if (CurrentProject == null)
            {
                return;
            }
            CurrentProject.Tasks.Clear();
            foreach (var process in CurrentProcessCollections)
            {
                SaveTask(process, false);
            }
            if (CurrentProject.Tasks.Any() == false &&
                MessageBox.Show(GlobalHelper.Get("key_316"), GlobalHelper.Get("key_151"), MessageBoxButton.OKCancel) ==
                MessageBoxResult.Cancel)
            {
                return;
            }

            if (isDefaultPosition)
            {
                Task.Factory.StartNew(() =>
                {
                    ControlExtended.SetBusy(ProgressBarState.Indeterminate, message: GlobalHelper.Get("key_308"));
                    ControlExtended.SafeInvoke(() =>
                    {
                        CurrentProject.Save(dataManager.DataCollections);
                    }, LogType.Important,
                                               GlobalHelper.Get("key_317"));
                    var pro = ConfigFile.GetConfig <DataMiningConfig>().Projects.FirstOrDefault();
                    if (pro != null)
                    {
                        pro.SavePath = CurrentProject.SavePath;
                    }
                    ControlExtended.SetBusy(ProgressBarState.NoProgress);
                });
            }
            else
            {
                CurrentProject.SavePath = null;
                ControlExtended.SafeInvoke(() => CurrentProject.Save(dataManager.DataCollections), LogType.Important,
                                           GlobalHelper.Get("key_318"));
            }
            ConfigFile.Config.SaveConfig();
        }
Пример #9
0
        /// <summary>
        /// Removes a hook from the current project
        /// </summary>
        /// <param name="hook"></param>
        public void RemoveHook(Hook hook)
        {
            Manifest manifest = CurrentProject.GetManifest(hook.AssemblyName);

            manifest.Hooks.Remove(hook);
            CurrentProject.Save(CurrentProjectFilename);

            foreach (TabPage tabpage in tabview.TabPages)
            {
                if (tabpage.Tag is HookViewControl && (tabpage.Tag as HookViewControl).Hook == hook)
                {
                    tabview.TabPages.Remove(tabpage);
                    break;
                }
            }

            TreeNode hooks = null;

            foreach (var node in objectview.Nodes)
            {
                if ((node as TreeNode).Text == "Hooks")
                {
                    hooks = node as TreeNode;
                    break;
                }
            }
            if (hooks == null)
            {
                return;
            }

            foreach (var node in hooks.Nodes)
            {
                if ((node as TreeNode).Tag == hook)
                {
                    hooks.Nodes.Remove(node as TreeNode);
                    break;
                }
            }
        }
Пример #10
0
 private void loadedassemblymenu_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     if (e.ClickedItem.Name == "removefromproject")
     {
         NodeAssemblyData data = (NodeAssemblyData)objectview.SelectedNode.Tag;
         CurrentProject.RemoveManifest(data.AssemblyName);
         CurrentProject.Save(CurrentProjectFilename);
         data.Included   = false;
         data.Loaded     = false;
         data.Definition = null;
         if (objectview.SelectedNode.Tag == null)
         {
             objectview.SelectedNode.Parent.Nodes.Remove(objectview.SelectedNode);
         }
         else
         {
             objectview.SelectedNode.ImageKey         = "cross.png";
             objectview.SelectedNode.SelectedImageKey = "cross.png";
             objectview.SelectedNode.Nodes.Clear();
         }
     }
 }
Пример #11
0
        /// <summary>
        /// Adds a hook to the current project
        /// </summary>
        /// <param name="hook"></param>
        public void AddHook(Hook hook)
        {
            Manifest manifest = CurrentProject.GetManifest(hook.AssemblyName);

            manifest.Hooks.Add(hook);
            CurrentProject.Save(CurrentProjectFilename);

            TreeNode hooks = null;

            foreach (var node in objectview.Nodes)
            {
                if ((node as TreeNode).Text == "Hooks")
                {
                    hooks = node as TreeNode;
                    break;
                }
            }
            if (hooks == null)
            {
                return;
            }

            TreeNode hooknode = new TreeNode(hook.Name);

            if (hook.Flagged)
            {
                hooknode.ImageKey         = "script_error.png";
                hooknode.SelectedImageKey = "script_error.png";
            }
            else
            {
                hooknode.ImageKey         = "script_lightning.png";
                hooknode.SelectedImageKey = "script_lightning.png";
            }
            hooknode.Tag = hook;
            hooks.Nodes.Add(hooknode);
        }
Пример #12
0
 public void Save(string fileName)
 {
     CurrentProject.FilePath = fileName;
     CurrentProject.Save(fileName);
 }
Пример #13
0
        public override void SaveConfigFile()
        {
            CurrentProject?.Save();

            ConfigFile.GetConfig().SaveConfig();
        }
Пример #14
0
        private void VerifyProject()
        {
            // Step 1: Check all included assemblies are intact
            // Step 2: Check all hooks are intact
            int missingassemblies = 0, missingmethods = 0, changedmethods = 0;

            foreach (Manifest manifest in CurrentProject.Manifests)
            {
                AssemblyDefinition assdef = LoadAssembly(manifest.AssemblyName);
                if (assdef == null)
                {
                    missingassemblies++;
                    foreach (var hook in manifest.Hooks)
                    {
                        hook.Flagged = true;
                    }
                }
                else
                {
                    foreach (var hook in manifest.Hooks)
                    {
                        var method = GetMethod(hook.AssemblyName, hook.TypeName, hook.Signature);
                        if (method == null)
                        {
                            missingmethods++;
                            hook.Flagged = true;
                        }
                        else
                        {
                            string hash = new Patching.ILWeaver(method.Body).Hash;
                            if (hash != hook.MSILHash)
                            {
                                changedmethods++;
                                hook.MSILHash = hash;
                                hook.Flagged  = true;
                            }
                        }
                    }
                }
            }

            if (missingassemblies > 0 || missingmethods > 0 || changedmethods > 0)
            {
                CurrentProject.Save(CurrentProjectFilename);
                if (missingassemblies > 1)
                {
                    MessageBox.Show(this, string.Format("{0} assemblies are missing from the target directory!", missingassemblies), "Oxide Patcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (missingassemblies == 1)
                {
                    MessageBox.Show(this, string.Format("{0} assembly is missing from the target directory!", missingassemblies), "Oxide Patcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                if (missingmethods > 0)
                {
                    MessageBox.Show(this, string.Format("{0} method(s) referenced by hooks no longer exist!", missingmethods), "Oxide Patcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                if (changedmethods > 0)
                {
                    MessageBox.Show(this, string.Format("{0} method(s) referenced by hooks have changed!", changedmethods), "Oxide Patcher", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #15
0
        public override bool Init()
        {
            base.Init();
            dockableManager    = MainFrmUI as IDockableManager;
            dataManager        = MainFrmUI.PluginDictionary["数据管理"] as IDataManager;
            propertyGridWindow = MainFrmUI.PluginDictionary["属性配置器"] as XFrmWorkPropertyGrid;


            ProcessCollection = new ObservableCollection <IDataProcess>();


            CurrentProcessTasks = new ObservableCollection <TaskBase>();
            BindingCommands     = new BindingAction("运行");
            var sysCommand = new BindingAction();

            sysCommand.ChildActions.Add(
                new Command(
                    "清空模块列表",
                    obj =>
            {
                if (MessageBox.Show("确定清空所有算法模块么?", "提示信息", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.OK)
                {
                    ProcessCollection.RemoveElementsNoReturn(d => true, RemoveOperation);
                }
            }, obj => true,
                    "clear"));

            sysCommand.ChildActions.Add(
                new Command(
                    "保存全部模块",
                    obj =>
            {
                if (MessageBox.Show("确定保存所有算法模块么?", "提示信息", MessageBoxButton.OKCancel) ==
                    MessageBoxResult.OK)
                {
                    foreach (var process in CurrentProcessCollections)
                    {
                        SaveTask(process, false);
                    }
                    CurrentProject.Save();
                }
            }, obj => true,
                    "clear"));

            BindingCommands.ChildActions.Add(sysCommand);

            var taskAction1 = new BindingAction();


            taskAction1.ChildActions.Add(new Command("加载本任务",
                                                     obj => (obj as ProcessTask).Load(true),
                                                     obj => obj is ProcessTask, "download"));


            taskAction1.ChildActions.Add(new Command("删除任务",
                                                     obj => CurrentProject.Tasks.Remove(obj as ProcessTask),
                                                     obj => obj is ProcessTask));
            taskAction1.ChildActions.Add(new Command("执行任务脚本",
                                                     (obj => (obj as ProcessTask).EvalScript()),
                                                     obj => (obj is ProcessTask) && CurrentProcessCollections.FirstOrDefault(d => d.Name == (obj as ProcessTask).Name) != null));

            BindingCommands.ChildActions.Add(taskAction1);
            var taskAction2 = new BindingAction("任务列表2");

            taskAction2.ChildActions.Add(new Command("开始任务",
                                                     obj =>
            {
                var task = obj as TaskBase;
                task.Start();
            },
                                                     obj =>
            {
                var task = obj as TaskBase;
                return(task != null && task.IsStart == false);
            }, "download"));

            taskAction2.ChildActions.Add(new Command("取消任务",
                                                     obj =>
            {
                var task = obj as TaskBase;
                if (task.IsStart)
                {
                    task.Cancel();
                }

                task.Remove();
            },
                                                     obj =>
            {
                var task = obj as TaskBase;
                return(task != null);
            }, "download"));


            var taskListAction = new BindingAction("任务列表命令");


            BindingCommands.ChildActions.Add(taskListAction);

            BindingCommands.ChildActions.Add(taskListAction);

            var processAction = new BindingAction();


            processAction.ChildActions.Add(new Command("配置", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                ShowConfigUI(process);
            }, obj => true, "settings"));
            processAction.ChildActions.Add(new Command("查看视图", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                (MainFrmUI as IDockableManager).ActiveModelContent(process);
            }, obj => true, "tv"));
            processAction.ChildActions.Add(new Command("拷贝", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                ProcessCollection.Remove(obj as IDataProcess);
                var item = GetOneInstance(process.TypeName, true, false);
                (process as IDictionarySerializable).DictCopyTo(item as IDictionarySerializable);
                item.Init();
                ProcessCollection.Add(item);
            }, obj => true, "new"));

            processAction.ChildActions.Add(new Command("移除", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }

                RemoveOperation(process);
                ProcessCollection.Remove(process);
                ShowConfigUI(null);
            }, obj => true, "delete"));

            processAction.ChildActions.Add(new Command("保存任务", obj =>
            {
                var process = obj as IDataProcess;
                if (process == null)
                {
                    return;
                }
                SaveTask(process, true);
            }, obj => obj is IDictionarySerializable));
            processAction.ChildActions.Add(new Command("显示并配置", obj =>
            {
                var process = GetProcess(obj);
                if (process == null)
                {
                    return;
                }
                var view = (MainFrmUI as IDockableManager).ViewDictionary.FirstOrDefault(d => d.Model == process);
                if (view == null)
                {
                    LoadProcessView(process);
                }
                (MainFrmUI as IDockableManager).ActiveModelContent(process);
                ShowConfigUI(process);
            }, obj => true, "delete"));


            BindingCommands.ChildActions.Add(processAction);
            BindingCommands.ChildActions.Add(taskAction2);
            var attributeactions = new BindingAction("模块");

            attributeactions.ChildActions.Add(new Command("添加", obj =>
            {
                var attr = obj as XFrmWorkAttribute;
                if (attr == null)
                {
                    return;
                }

                var process = GetOneInstance(attr.MyType.Name, newOne: true, isAddUI: true);
                process.Init();
            }));
            BindingCommands.ChildActions.Add(attributeactions);

            var config = ConfigFile.GetConfig <DataMiningConfig>();

            if (config.Projects.Any())
            {
                var project = config.Projects.FirstOrDefault();
                if (project != null)
                {
                    ControlExtended.SafeInvoke(() =>
                    {
                        currentProject = ProjectItem.LoadProject(project.SavePath);
                        NotifyCurrentProjectChanged();
                    }, LogType.Info, "加载默认工程");
                }
            }

            if (MainDescription.IsUIForm)
            {
                ProgramNameFilterView =
                    new ListCollectionView(PluginProvider.GetPluginCollection(typeof(IDataProcess)).ToList());

                ProgramNameFilterView.GroupDescriptions.Clear();
                ProgramNameFilterView.GroupDescriptions.Add(new PropertyGroupDescription("GroupName"));
                var taskView    = PluginProvider.GetObjectInstance <ICustomView>("任务管理视图");
                var userControl = taskView as UserControl;
                if (userControl != null)
                {
                    userControl.DataContext = this;
                    ((INotifyCollectionChanged)CurrentProcessTasks).CollectionChanged += (s, e) =>
                    {
                        ControlExtended.UIInvoke(() => {
                            if (e.Action == NotifyCollectionChangedAction.Add)
                            {
                                dockableManager.ActiveThisContent("任务管理视图");
                            }
                        });
                    }
                    ;
                    dockableManager.AddDockAbleContent(taskView.FrmState, this, taskView, "任务管理视图");
                }
                ProcessCollectionView = new ListCollectionView(ProcessCollection);
                ProcessCollectionView.GroupDescriptions.Clear();
                ProcessCollectionView.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));


                ProjectTaskList = new ListCollectionView(CurrentProject.Tasks);
                ProjectTaskList.GroupDescriptions.Clear();

                ProjectTaskList.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));


                OnPropertyChanged("ProjectTaskList");
                ProjectTaskList = new ListCollectionView(CurrentProject.Tasks);
                ProjectTaskList.GroupDescriptions.Clear();

                ProjectTaskList.GroupDescriptions.Add(new PropertyGroupDescription("TypeName"));
                OnPropertyChanged("ProjectTaskList");
            }

            var file = MainFrmUI.CommandCollection.FirstOrDefault(d => d.Text == "文件");

            file.ChildActions.Add(new BindingAction("新建项目", obj => CreateNewProject()));
            file.ChildActions.Add(new BindingAction("加载项目", obj => LoadProject()));
            file.ChildActions.Add(new BindingAction("保存项目", obj => SaveCurrentProject()));
            file.ChildActions.Add(new BindingAction("项目另存为", obj => SaveCurrentProject(false)));

            return(true);
        }
Пример #16
0
        public override void SaveConfigFile()
        {
            CurrentProject?.Save(dataManager.DataCollections);

            ConfigFile.GetConfig().SaveConfig();
        }
Пример #17
0
 private void MnSave_Click(object sender, EventArgs e)
 {
     currentProject.Save();
 }