示例#1
0
        private void OnAddFolder(object sender, RoutedEventArgs e)
        {
            TreeViewItem parent = treeView.SelectedItem as TreeViewItem;
            int          index  = 0;

            if (parent == null)
            {
                parent = treeView.Items[0] as TreeViewItem;
            }

            object o = parent.Tag;

            if (o is Setup)
            {
                TreeViewItem child = parent;
                parent = parent.Parent as TreeViewItem;
                index  = parent.Items.IndexOf(child) + 1;
            }

            SetupFolder  folder = new SetupFolder();
            TreeViewItem item   = MakeFolderItem(folder);

            parent.Items.Insert(index, item);
            item.IsSelected = true;
            item.Focus();
            UpdateButtons();
            Modified = true;
        }
 public void PopulateList(SetupFolder folder, Action <SetupFolder> navigateForward, Action navigateBack = null)
 {
     this.navigateForward = navigateForward;
     this.navigateBack    = navigateBack;
     this.folder          = folder;
     list.Children.Clear();
     if (folder.Parent != null)
     {
         TerrariaSetupFolder control = new TerrariaSetupFolder(folder.Parent, true, () => {
             navigateBack();
         });
         list.Children.Add(control);
     }
     foreach (object bothEntry in folder.Entries)
     {
         if (bothEntry is SetupFolder)
         {
             SetupFolder         subFolder = (SetupFolder)bothEntry;
             TerrariaSetupFolder control   = new TerrariaSetupFolder(subFolder, false, () => {
                 navigateForward(subFolder);
             });
             list.Children.Add(control);
         }
         else if (bothEntry is Setup)
         {
             Setup entry = (Setup)bothEntry;
             TerrariaSetupEntry control = new TerrariaSetupEntry(entry);
             list.Children.Add(control);
         }
     }
 }
示例#3
0
        public SetupFolder GenerateHierarchy()
        {
            TreeViewItem rootItem   = (TreeViewItem)treeView.Items[0];
            SetupFolder  rootFolder = (SetupFolder)rootItem.Tag;

            PopulateHierarchy(rootItem, rootFolder);
            return(rootFolder);
        }
        public EditFolderWindow(SetupFolder folder)
        {
            InitializeComponent();

            // Init icon combo box

            int index       = 0;
            int folderIndex = -1;

            foreach (var pair in Setup.SetupIcons)
            {
                comboBoxIcon.Items.Add(pair.Key);
                if (folder.Icon == pair.Key)
                {
                    comboBoxIcon.SelectedIndex = index;
                }
                if (pair.Key == "Folder")
                {
                    folderIndex = index;
                }
                index++;
            }
            if (comboBoxIcon.SelectedIndex == -1 && folderIndex != -1)
            {
                comboBoxIcon.SelectedIndex = folderIndex;
            }

            textBoxName.Text = folder.Name;
            if (Setup.SetupIcons.ContainsKey(folder.Icon))
            {
                comboBoxIcon.Visibility           = Visibility.Visible;
                textBoxCustomIcon.Visibility      = Visibility.Hidden;
                buttonBrowseCustomIcon.Visibility = Visibility.Hidden;

                checkBoxCustomIcon.IsChecked = false;
            }
            else
            {
                textBoxCustomIcon.Text            = folder.Icon;
                comboBoxIcon.Visibility           = Visibility.Hidden;
                textBoxCustomIcon.Visibility      = Visibility.Visible;
                buttonBrowseCustomIcon.Visibility = Visibility.Visible;

                checkBoxCustomIcon.IsChecked = true;
            }

            UpdateIcon(folder.Icon);

            // Remove quotes from "Copy Path" command on paste
            DataObject.AddPastingHandler(textBoxCustomIcon, OnTextBoxQuotesPaste);

            // Disable drag/drop text in textboxes so you can scroll their contents easily
            DataObject.AddCopyingHandler(textBoxName, OnTextBoxCancelDrag);
            DataObject.AddCopyingHandler(textBoxCustomIcon, OnTextBoxCancelDrag);
        }
示例#5
0
 private void PopulateHierarchy(TreeViewItem parent, SetupFolder folder)
 {
     folder.Entries.Clear();
     foreach (var itemObj in parent.Items)
     {
         TreeViewItem item  = (TreeViewItem)itemObj;
         ISetup       setup = item.Tag as ISetup;
         folder.Entries.Add(setup);
         if (setup is SetupFolder)
         {
             ((SetupFolder)setup).Parent = folder;
             PopulateHierarchy(item, (SetupFolder)setup);
         }
     }
 }
示例#6
0
 private void Populate(TreeViewItem parent, SetupFolder folder)
 {
     foreach (object o in folder.Entries)
     {
         if (o is SetupFolder)
         {
             TreeViewItem item = MakeFolderItem(o as SetupFolder);
             parent.Items.Add(item);
             Populate(item, o as SetupFolder);
         }
         else if (o is Setup)
         {
             parent.Items.Add(MakeSetupItem(o as Setup));
         }
     }
 }
示例#7
0
        public void Populate(SetupFolder folder, SetupTypes setupType)
        {
            folder         = folder.CloneFolder();
            this.setupType = setupType;
            TreeViewItem root = MakeFolderItem(folder, true);

            treeView.Items.Add(root);
            Populate(root, folder);
            switch (setupType)
            {
            case SetupTypes.Game: imageAddSetup.Source = iconAddGame; break;

            case SetupTypes.Server: imageAddSetup.Source = iconAddServer; break;

            case SetupTypes.Tool: imageAddSetup.Source = iconAddTool; break;
            }
            buttonAddSetup.ToolTip = "Add " + setupType + " Setup";
            UpdateButtons();
        }
        public static bool ShowDialog(Window owner, SetupFolder folder)
        {
            EditFolderWindow window = new EditFolderWindow(folder);

            window.Owner = owner;
            var result = window.ShowDialog();

            if (result.HasValue && result.Value)
            {
                folder.Name = window.textBoxName.Text;
                if (window.checkBoxCustomIcon.IsChecked.Value)
                {
                    folder.Icon = window.textBoxCustomIcon.Text;
                }
                else
                {
                    folder.Icon = window.comboBoxIcon.SelectedItem as string;
                }
                return(true);
            }
            return(false);
        }
        public TerrariaSetupFolder(SetupFolder folder, bool isParent, Action navigate)
        {
            InitializeComponent();

            folder.Entry  = this;
            this.navigate = navigate;
            this.folder   = folder;
            SetupOption option = new SetupOption("", "", navigate);

            if (isParent)
            {
                option.Tooltip       = "Go back to the parent folder";
                option.Icon          = "FolderLeave";
                labelName.Content    = "Go Back";
                labelEntries.Content = "Parent: " + folder.Name;
            }
            else
            {
                option.Tooltip       = "Open the subfolder";
                option.Icon          = "FolderEnter";
                labelName.Content    = folder.Name;
                labelEntries.Content = "Folder: " + folder.Entries.Count + " Entries";

                TerrariaSetupOptionButton button2 = new TerrariaSetupOptionButton(option);
                stackPanelOptions.Children.Add(button2);

                option = new SetupOption("Edit Folder", "Gear", folder.EditFolder);
            }

            TerrariaSetupOptionButton button = new TerrariaSetupOptionButton(option);

            stackPanelOptions.Children.Add(button);

            BitmapSource bitmap = folder.LoadIcon();

            imageIcon.Source = bitmap;
            imageIcon.Width  = Math.Min(68, bitmap.PixelWidth);
            imageIcon.Height = Math.Min(68, bitmap.PixelHeight);
        }
示例#10
0
        private TreeViewItem MakeFolderItem(SetupFolder folder, bool root = false)
        {
            TreeViewItem item = new TreeViewItem();

            item.Tag        = folder;
            item.AllowDrop  = true;
            item.IsExpanded = true;
            item.Expanded  += (s, _) => {
                UpdateItem((TreeViewItem)s);
            };
            item.Collapsed += (s, _) => {
                UpdateItem((TreeViewItem)s);
            };

            StackPanel stackPanel = new StackPanel();

            stackPanel.Orientation      = Orientation.Horizontal;
            stackPanel.IsHitTestVisible = false;
            stackPanel.Margin           = new Thickness(2);
            item.Header = stackPanel;

            Image image = new Image();

            image.VerticalAlignment = VerticalAlignment.Center;
            image.Width             = 16;
            image.Height            = 16;
            image.Source            = iconFolderOpen;
            stackPanel.Children.Add(image);

            TextBlock text = new TextBlock();

            text.VerticalAlignment = VerticalAlignment.Center;
            text.Text   = folder.Name;
            text.Margin = new Thickness(5, 1, 2, 1);
            stackPanel.Children.Add(text);

            return(item);
        }
示例#11
0
        private void UpdateItem(TreeViewItem item)
        {
            object o = item.Tag;

            StackPanel stackPanel = (StackPanel)item.Header;
            Image      image      = (Image)stackPanel.Children[0];
            TextBlock  name       = (TextBlock)stackPanel.Children[1];

            if (o is SetupFolder)
            {
                SetupFolder folder = (SetupFolder)o;
                name.Text    = folder.Name;
                image.Source = (item.IsExpanded ? iconFolderOpen : iconFolderClosed);
            }
            else if (o is Setup)
            {
                TextBlock details = (TextBlock)stackPanel.Children[2];

                Setup setup = (Setup)o;

                name.Text = setup.Name;

                if (!string.IsNullOrWhiteSpace(setup.Details))
                {
                    details.Text = " (" + setup.Details + ")";
                }
                else
                {
                    details.Text = "";
                }

                if (setupType == SetupTypes.Game)
                {
                    image.Source = (((Game)setup).IsTMod ? iconGameTMod : iconGame);
                }
            }
        }
示例#12
0
        private void NavigateForward(Grid gridList, Stack <TerrariaSetupList> stack, SetupFolder folder)
        {
            TerrariaSetupList setupList = new TerrariaSetupList();

            setupList.PopulateList(folder, (folder2) => {
                NavigateForward(gridList, stack, folder2);
            }, () => {
                NavigateBack(gridList, stack);
            });
            var last = stack.Peek();

            stack.Push(setupList);
            gridList.Children.Add(setupList);
            if (!Config.DisableTransitions)
            {
                last.LeaveFolder(false, gridList.ActualWidth);
                setupList.EnterFolder(false, gridList.ActualWidth);
            }
            else
            {
                last.Visibility = Visibility.Hidden;
            }
            UpdateFolder();
        }
示例#13
0
        /// <summary>
        /// Executa uma programa a partir da sua instalação
        /// </summary>
        /// <param name="basePath"></param>
        /// <returns></returns>
        public static bool Run(string basePath, out string message)
        {
            if (string.IsNullOrEmpty(basePath) ||
                !Directory.Exists(basePath))
            {
                message = "Parâmetro basePath vazio";
                return(false);
            }
            Program program;
            bool    success = false;

            message = "";
            try
            {
                program = Program.FromInstalledFolder(basePath);

                if (program.JustOneInstance && InstancesRunning(program.Main.FileName))
                {
                    Log.Add(program.Main.FileName + " JÁ EM EXECUÇÃO", "ERRO");
                    message = "Instância já em execução";
                    return(false);
                }


                ProcessWorker = new BackgroundWorker();

                IsRunning = true;
                try
                {
                    Icon icon = Icon.ExtractAssociatedIcon(Path.Combine(basePath, program.Main.FileName));
                    NotifyLoader.UpdateIcon(UpdateIconType.SetIcon, icon);
                }
                catch (Exception e)
                {
                    Log.Add(e.Message, "EXCEPTION");
                }
                ProcessWorker.DoWork += (object sender, DoWorkEventArgs e) =>
                {
                    currentProcess = new Process();
                    NotifyLoader.UpdateIcon(UpdateIconType.ProcessInfo, currentProcess);

                    currentProcess.StartInfo.FileName         = program.Main.FileName;
                    currentProcess.StartInfo.WorkingDirectory = basePath;

                    if (!string.IsNullOrEmpty(program.Arguments))
                    {
                        currentProcess.StartInfo.Arguments = program.Arguments;
                    }
                    currentProcess.Exited += (object _sender, EventArgs _e) =>
                    {
                        if (currentProcess == null)
                        {
                            //TODO: Registrar log de saída sem processo definido
                        }
                        else
                        {
                            //TODO: Registrar log de saída com data/hora de início, data/hora de saída e ExitCode
                        }
                        NotifyLoader.UpdateIcon(UpdateIconType.ProcessInfo, (Process)null);
                    };

                    currentProcess.EnableRaisingEvents = true;
                    SetupFolder setupFolder = new SetupFolder(basePath);
                    DoStats     stats       = new DoStats(setupFolder.DBPath);
                    try
                    {
                        Log.Add(program.Main.FileName, "START");
                        //DONE: Registrar log STARTING
                        NotifyLoader.UpdateIcon(UpdateIconType.ShowBaloonInfo, program.ProgramName);
                        currentProcess.Start();
                        currentProcess.WaitForExit();
                        stats.RegisterProcess(currentProcess);
                        NotifyLoader.UpdateIcon(UpdateIconType.ShowBaloonInfo, program.ProgramName + " FINALIZANDO");
                        Log.Add(program.Main.FileName + "\n" + currentProcess.StartTime + " -> " + currentProcess.ExitTime + "\n" +
                                "ExitCode: " + currentProcess.ExitCode + "\n" +
                                "TotalProcessorTime: " + currentProcess.TotalProcessorTime
                                , "STOP");
                        //DONE: Registrar log STARTED
                        success = true;
                    }
                    catch (Exception ex)
                    {
                        Log.Add(ex.Message, "EXCEPTION");
                        //DONE: Registrar log START EXCEPTION
                    }
                    IsRunning = false;
                    NotifyLoader.UpdateIcon(UpdateIconType.RestoreIcon, null);
                };
                ProcessWorker.RunWorkerAsync();
            }
            catch (Exception e)
            {
                message = "Exceção durante a execução: " + e.Message;
            }
            if (success)
            {
                message = "Execução encerrou";
            }

            return(success);
        }
示例#14
0
        public void TestSetupFolder()
        {
            SetupFolder sf = new SetupFolder(".");

            Console.WriteLine(sf.SetupPath);
        }