示例#1
0
        private static ImageSource CreateCustomImageSource(PackIconMaterialKind kind, Brush brush)
        {
            var extension = new MaterialImageExtension(kind);

            extension.Brush = brush;
            return(extension.ProvideValue(null) as ImageSource);
        }
示例#2
0
        /// <summary>
        /// Sets the associated <see cref="PackIconMaterialKind"/> to the <see cref="TextTarget"/>.
        /// </summary>
        /// <param name="icon"></param>
        /// <param name="target"></param>
        public void SetIcon(PackIconMaterialKind icon = PackIconMaterialKind.None, TextTarget target = TextTarget.StatusBarText)
        {
            // If it doesn't have access then execute the same function on the UI thread, otherwise just run it.
            if (!Application.Current.Dispatcher.CheckAccess())
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() => SetIcon(icon, target)));
                return;
            }

            try
            {
                switch (target)
                {
                case TextTarget.StatusBarText:
                    App.MainWindow.ViewModel.StatusBarTextIconVisibility = icon == PackIconMaterialKind.None ? Visibility.Collapsed : Visibility.Visible;
                    App.MainWindow.ViewModel.StatusBarTextIconKind       = icon;
                    break;

                default:
                    App.Conveyor.EchoError($"SetIcon: TextTarget {(int)target} was not found.");
                    break;
                }
            }
            catch (Exception ex)
            {
                App.Conveyor.EchoError($"An error occurred setting a status bar icon: {ex.Message}");
            }
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="SettingViewModel" /> class.
        /// </summary>
        /// <param name="settingSource">The setting source.</param>
        /// <param name="property">The property name of the setting.</param>
        /// <param name="title">The title.</param>
        /// <param name="description">The description.</param>
        /// <param name="defaultValue">The default value.</param>
        /// <param name="icon">The icon.</param>
        /// <param name="minValue">The minimum value.</param>
        /// <param name="maxValue">The maximum value.</param>
        /// <exception cref="ArgumentException">
        ///     maxValue has to be higher or equal than minValue
        ///     or
        ///     minValue has to be lower or equal than minValue
        /// </exception>
        public SettingViewModel(object settingSource, string property, string title, string description,
                                PackIconMaterialKind icon, object defaultValue, int minValue = 0, int maxValue = 0)
        {
            if (maxValue < minValue)
            {
                throw new ArgumentException($"{nameof(maxValue)} has to be higher or equal than {nameof(minValue)}");
            }

            if (minValue > maxValue)
            {
                throw new ArgumentException($"{nameof(minValue)} has to be lower or equal than {nameof(maxValue)}");
            }

            if (settingSource.GetType().GetProperty(property).GetValue(settingSource, null).GetType() !=
                defaultValue.GetType())
            {
                throw new ArgumentException("Default type and settings type have to be equal");
            }

            _defaultValue  = defaultValue;
            _settingSource = settingSource;
            _property      = property;
            Title          = title;
            Description    = description;
            Icon           = icon;

            _minValue = minValue;
            _maxValue = maxValue;

            Options = new Dictionary <Enum, string>();

            SetupEnum();
            SetDefaultValue();
        }
示例#4
0
 /// <summary>
 /// Default constructor for an action
 /// </summary>
 /// <param name="header">The item header</param>
 /// <param name="iconKind">The item icon kind</param>
 /// <param name="command">The item command</param>
 /// <param name="minUserLevel">The minimum user level for the action</param>
 public ActionItemViewModel(string header, PackIconMaterialKind iconKind, ICommand command, UserLevel minUserLevel = UserLevel.Normal)
 {
     Header       = header;
     IconKind     = iconKind;
     Command      = command;
     MinUserLevel = minUserLevel;
 }
示例#5
0
        private void SetDashboardButton(string color, string name, int count, PackIconMaterialKind iconKind, DashboardButton dashboardButton)
        {
            BrushConverter conv = new BrushConverter();

            dashboardButton.ButtonName  = name;
            dashboardButton.ColorButton = conv.ConvertFromString(color) as SolidColorBrush;
            dashboardButton.ItemsNumber = count;
            dashboardButton.IconKind    = iconKind;
        }
示例#6
0
        public ToolboxItem(PackIconMaterialKind icon, string name, string pageName, bool isUseExplorer = true, double width = 600, double height = 700)
        {
            Icon = icon;
            Name = name;

            _width         = width;
            _height        = height;
            _pageName      = pageName;
            _isUseExplorer = isUseExplorer;
        }
 public void KeepAccoutSigned()
 {
     if (LoginKeepSigned == PackIconMaterialKind.CheckboxBlankOutline)
     {
         LoginKeepSigned = PackIconMaterialKind.CheckboxMarked;
     }
     else
     {
         LoginKeepSigned = PackIconMaterialKind.CheckboxBlankOutline;
     }
 }
        /// <summary>
        /// Constructor for a category which is visible
        /// </summary>
        /// <param name="games">The games in this category</param>
        /// <param name="displayName">The display name</param>
        /// <param name="iconKind">The category icon</param>
        public GameCategoryViewModel(IEnumerable <Games> games, LocalizedString displayName, PackIconMaterialKind iconKind)
        {
            // Set properties
            Games       = games.ToArray();
            DisplayName = displayName;
            IconKind    = iconKind;
            IsMaster    = false;

            // Create properties
            InstalledGames    = new ObservableCollection <GameDisplayViewModel>();
            NotInstalledGames = new ObservableCollection <GameDisplayViewModel>();
        }
示例#9
0
        internal static MenuItem CreateGenericButton(ICommand command, string key, PackIconMaterialKind icon)
        {
            MenuItem b = new MenuItem()
            {
                Header = LocalizationManager.Current.Interface[key]
            };

            b.Command = command;
            b.Icon    = new PackIconMaterial()
            {
                Kind = icon
            };
            (b.Icon as PackIconMaterial).SetResourceReference(PackIconMaterial.ForegroundProperty, "AccentColor");
            return(b);
        }
示例#10
0
        /// <summary>
        /// Sets the text on a supported UI text element.
        /// </summary>
        /// <param name="buf"></param>
        /// <param name="target"></param>
        /// <param name="icon"></param>
        public void SetText(string buf, TextTarget target = TextTarget.StatusBarText, PackIconMaterialKind icon = PackIconMaterialKind.None)
        {
            // If it doesn't have access then execute the same function on the UI thread, otherwise just run it.
            if (!Application.Current.Dispatcher.CheckAccess())
            {
                Application.Current.Dispatcher.BeginInvoke(new Action(() => SetText(buf, target, icon)));
                return;
            }

            switch (target)
            {
            case TextTarget.StatusBarText:
                App.MainWindow.ViewModel.StatusBarText = buf ?? "";
                break;

            default:
                App.Conveyor.EchoError($"SetText: TextTarget {((int)target).ToString()} was not found.");
                break;
            }

            this.SetIcon(icon, target);
        }
示例#11
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="header">The link header</param>
 /// <param name="path">The link file path</param>
 /// <param name="icon">The icon to use, or none to use the file icon</param>
 public GameFileLink(string header, FileSystemPath path, PackIconMaterialKind icon = PackIconMaterialKind.None)
 {
     Header = header;
     Path   = path;
     Icon   = icon;
 }
 public LoginPageViewModel()
 {
     LoginKeepSigned = PackIconMaterialKind.CheckboxBlankOutline;
 }
 public static void SetIconKind(System.Windows.Controls.TabItem obj, PackIconMaterialKind value) => obj.SetValue(IconKindProperty, value);
示例#14
0
        private async void CreateScriptMetaFilesCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            // Force update of script interface controls (if changed)
            ScriptUpdateButton.Focus();

            // Must be filtered by ScriptCommand_CanExecute before
            if (Model.WorkInProgress)
            {
                Global.Logger.SystemWrite(new LogInfo(LogState.CriticalError, $"Race condition with {nameof(Model.WorkInProgress)} happened in {nameof(ScriptUpdateCommand_Executed)}"));
                return;
            }

            // Get instances of Script and Project
            Script  targetScript = Model.CurMainTree.Script;
            Project p            = Model.CurMainTree.Script.Project;

            // Define local variables
            Script[]       targetScripts;
            List <LogInfo> logs = new List <LogInfo>();

            // Turn on progress ring
            Model.WorkInProgress = true;
            int successCount = 0;
            int errorCount   = 0;

            try
            {
                // Populate BuildTree
                ProjectTreeItemModel treeRoot = MainViewModel.PopulateOneTreeItem(targetScript, null, null);
                Model.BuildTreeItems.Clear();
                if (targetScript.Type == ScriptType.Directory || targetScript.IsMainScript)
                { // Update a list of scripts
                    // We have to search in p.AllScripts rather than in ProjectTreeItemModel to find hidden scripts
                    // (ProjectTreeItemModel only contains visible scripts)
                    if (targetScript.IsMainScript)
                    {
                        targetScripts = p.AllScripts.ToArray();
                    }
                    else
                    {
                        targetScripts = p.AllScripts
                                        .Where(x => x.TreePath.StartsWith(targetScript.TreePath, StringComparison.OrdinalIgnoreCase))
                                        .ToArray();
                    }

                    MainViewModel.ScriptListToTreeViewModel(p, targetScripts, false, treeRoot);
                    targetScripts = targetScripts.Where(x => x.Type != ScriptType.Directory).ToArray();
                    if (targetScripts.Length == 0)
                    {
                        // Ask user for confirmation
                        MessageBox.Show(this,
                                        $"Directory [{targetScript.Title}] does not contain any scripts.",
                                        "No child scripts",
                                        MessageBoxButton.OK,
                                        MessageBoxImage.Warning);
                        return;
                    }
                }
                else
                {
                    targetScripts = new Script[] { targetScript };
                }

                Model.BuildTreeItems.Add(treeRoot);
                Model.CurBuildTree = null;

                // Switch to Build View
                Model.BuildScriptProgressVisibility = Visibility.Collapsed;
                Model.BuildFullProgressMax          = targetScripts.Length;
                Model.BuildFullProgressValue        = 0;
                Model.SwitchNormalBuildInterface    = false;
                // I do not know why, but this line must come after SwitchNormalBuildInterface.
                Model.BuildEchoMessage = "Creating meta files...";

                Stopwatch watch = Stopwatch.StartNew();

                // Run Updater
                int idx = 0;
                foreach (Script sc in targetScripts)
                {
                    // Display script information
                    idx += 1;
                    Model.BuildFullProgressValue = idx;
                    Model.DisplayScriptTexts(sc, null);
                    Model.ScriptTitleText  = Model.ScriptTitleText;
                    Model.BuildEchoMessage = $"Creating meta files... ({idx * 100 / targetScripts.Length}%)";
                    Application.Current?.Dispatcher?.BeginInvoke((Action)(() =>
                    {
                        Model.DisplayScriptLogo(sc);

                        // BuildTree is empty -> return
                        if (Model.BuildTreeItems.Count == 0)
                        {
                            return;
                        }

                        if (Model.CurBuildTree != null)
                        {
                            Model.CurBuildTree.Focus = false;
                        }
                        Model.CurBuildTree = ProjectTreeItemModel.FindScriptByRealPath(Model.BuildTreeItems[0], sc.RealPath);
                        if (Model.CurBuildTree != null)
                        {
                            Model.CurBuildTree.Focus = true;
                        }
                    }));

                    // Do the real job
                    string destJsonFile = Path.ChangeExtension(sc.RealPath, ".meta.json");
                    try
                    {
                        await UpdateJson.CreateScriptUpdateJsonAsync(sc, destJsonFile);

                        logs.Add(new LogInfo(LogState.Success, $"Created meta file for [{sc.Title}]"));
                        successCount += 1;
                    }
                    catch (Exception ex)
                    {
                        logs.Add(new LogInfo(LogState.Error, $"Unable to create meta file for [{sc.Title}] - {Logger.LogExceptionMessage(ex)}"));
                        errorCount += 1;
                    }
                }

                // Log messages
                Logger.SystemWrite(logs);

                watch.Stop();
                TimeSpan t = watch.Elapsed;
                Model.StatusBarText = $"Updated {targetScript.Title} ({t:h\\:mm\\:ss})";
            }
            finally
            {
                // Turn off progress ring
                Model.WorkInProgress = false;

                // Build Ended, Switch to Normal View
                Model.BuildScriptProgressVisibility = Visibility.Visible;
                Model.BuildEchoMessage           = string.Empty;
                Model.SwitchNormalBuildInterface = true;
                Model.DisplayScript(Model.CurMainTree.Script);
            }

            PackIconMaterialKind msgBoxIcon = PackIconMaterialKind.Information;
            StringBuilder        b          = new StringBuilder(targetScripts.Length + 4);

            b.AppendLine($"Created [{successCount}] script meta files.");

            foreach (LogInfo log in logs.Where(x => x.State == LogState.Success))
            {
                b.AppendLine($"- {log.Message}");
            }

            if (0 < errorCount)
            { // Failure
                b.AppendLine();
                b.AppendLine($"Failed to create [{errorCount}] script meta files");
                foreach (LogInfo log in logs.Where(x => x.State == LogState.Error))
                {
                    b.AppendLine($"- {log.Message}");
                }

                msgBoxIcon = PackIconMaterialKind.Alert;
            }

            const string   msgTitle = "Script Meta Files Report";
            TextViewDialog dialog   = new TextViewDialog(this, msgTitle, msgTitle, b.ToString(), msgBoxIcon);

            dialog.ShowDialog();
        }
示例#15
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="header">The link header</param>
 /// <param name="path">The link path</param>
 /// <param name="icon">The icon to use</param>
 public GamePurchaseLink(string header, string path, PackIconMaterialKind icon = PackIconMaterialKind.BriefcaseOutline)
 {
     Header = header;
     Path   = path;
     Icon   = icon;
 }
示例#16
0
 public ItemMenu(string header, PackIconMaterialKind icon, UserControl screen = null)
 {
     Header = header;
     Screen = screen;
     Icon   = icon;
 }
 private bool FilterMaterialKinds(PackIconMaterialKind packIconMaterialKind)
 {
     return string.IsNullOrWhiteSpace(MaterialFilterTerm) || packIconMaterialKind.ToString().IndexOf(MaterialFilterTerm, StringComparison.CurrentCultureIgnoreCase) >= 0;
 }
示例#18
0
 public ItemMenu(string header, List <SubItem> subItems, PackIconMaterialKind icon)
 {
     Header   = header;
     SubItems = subItems;
     Icon     = icon;
 }
示例#19
0
 private bool FilterMaterialKinds(PackIconMaterialKind packIconMaterialKind)
 {
     return(string.IsNullOrWhiteSpace(MaterialFilterTerm) || packIconMaterialKind.ToString().IndexOf(MaterialFilterTerm, StringComparison.CurrentCultureIgnoreCase) >= 0);
 }
 public GenericIcon(PackIconMaterialKind iconKind, Brush iconColor)
 {
     IconKind  = iconKind;
     IconColor = iconColor;
 }
 public static void SetIconKind(Button obj, PackIconMaterialKind value) => obj.SetValue(IconKindProperty, value);
示例#22
0
 /// <summary>
 /// Default constructor for an action
 /// </summary>
 /// <param name="header">The item header</param>
 /// <param name="iconKind">The item icon kind</param>
 /// <param name="command">The item command</param>
 /// <param name="minUserLevel">The minimum user level for the action</param>
 public OverflowButtonItemViewModel(string header, PackIconMaterialKind iconKind, ICommand command, UserLevel minUserLevel = UserLevel.Normal) : base(header, iconKind, command, minUserLevel)
 {
 }
 public AssetPickerAttribute(Type assetType, string key, PackIconMaterialKind icon)
 {
     AssetType = assetType;
     this.Key  = key;
     this.Icon = icon;
 }
示例#24
0
 public static IconoMenuEstatico Crear(PackIconMaterialKind clase) => new IconoMenuEstatico(new PackIconMaterial {
     Kind = clase
 });
示例#25
0
 public static void SetTrailingIcon(DependencyObject element, PackIconMaterialKind value)
 => element.SetValue(TrailingIconProperty, value);
示例#26
0
        private async void ScriptUpdateCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            // Force update of script interface controls (if changed)
            ScriptUpdateButton.Focus();

            // Must be filtered by ScriptCommand_CanExecute before
            if (Model.WorkInProgress)
            {
                Global.Logger.SystemWrite(new LogInfo(LogState.CriticalError, $"Race condition with {nameof(Model.WorkInProgress)} happened in {nameof(ScriptUpdateCommand_Executed)}"));
                return;
            }

            // Get instances of Script and Project
            Script  targetScript = Model.CurMainTree.Script;
            Project p            = Model.CurMainTree.Script.Project;
            // Do not apply updateMultipleScript to MainScript, because users should use project update for this job.
            bool updateMultipleScript = targetScript.Type == ScriptType.Directory;

            if (!updateMultipleScript && !targetScript.IsUpdateable)
            {
                Global.Logger.SystemWrite(new LogInfo(LogState.CriticalError, $"Race condition with {nameof(Script.IsUpdateable)} happened in {nameof(ScriptUpdateCommand_Executed)}"));
                return;
            }

            // Define local variables
            Script[] targetScripts = null;
            // Update one script
            Script  newScript  = null;
            LogInfo updaterLog = null;

            // Update scripts
            Script[]  newScripts  = null;
            LogInfo[] updaterLogs = null;

            // Turn on progress ring
            Model.WorkInProgress = true;
            try
            {
                // Populate BuildTree
                ProjectTreeItemModel treeRoot = MainViewModel.PopulateOneTreeItem(targetScript, null, null);
                Model.BuildTreeItems.Clear();
                if (updateMultipleScript)
                { // Update a list of scripts
                    // We have to search in p.AllScripts rather than in ProjectTreeItemModel to find hidden scripts
                    // (ProjectTreeItemModel only contains visible scripts)
                    targetScripts = p.AllScripts
                                    .Where(x => x.TreePath.StartsWith(targetScript.TreePath, StringComparison.OrdinalIgnoreCase) &&
                                           x.IsUpdateable)
                                    .ToArray();
                    MainViewModel.ScriptListToTreeViewModel(p, targetScripts, false, treeRoot);
                    targetScripts = targetScripts.Where(x => x.Type != ScriptType.Directory).ToArray();
                    if (targetScripts.Length == 0)
                    {
                        // Ask user for confirmation
                        MessageBox.Show(this,
                                        $"Directory [{targetScript.Title}] does not contain any scripts that are able to be updated.",
                                        "No updateable scripts",
                                        MessageBoxButton.OK,
                                        MessageBoxImage.Warning);
                        return;
                    }
                }

                Model.BuildTreeItems.Add(treeRoot);
                Model.CurBuildTree = null;
                Debug.Assert(updateMultipleScript && targetScript != null && targetScripts != null ||
                             !updateMultipleScript && targetScript != null && targetScripts == null,
                             $"Check {updateMultipleScript}");

                // Ask user for confirmation
                string targetScriptCountStr;
                if (updateMultipleScript)
                {
                    targetScriptCountStr = targetScripts.Length == 1 ? "1 script" : $"{targetScripts.Length} scripts";
                }
                else
                {
                    targetScriptCountStr = $"script [{targetScript.Title}]";
                }
                MessageBoxResult result = MessageBox.Show(this,
                                                          $"Are you sure you want to update {targetScriptCountStr}?",
                                                          "Continue?",
                                                          MessageBoxButton.YesNo,
                                                          MessageBoxImage.Question);
                if (result == MessageBoxResult.No)
                {
                    return;
                }

                // Switch to Build View
                Model.BuildScriptFullProgressVisibility = Visibility.Collapsed;
                Model.SwitchNormalBuildInterface        = false;

                Stopwatch watch = Stopwatch.StartNew();

                // Run Updater
                string      customUserAgent = Global.Setting.General.UseCustomUserAgent ? Global.Setting.General.CustomUserAgent : null;
                FileUpdater updater         = new FileUpdater(p, Model, customUserAgent);
                if (updateMultipleScript) // Update a list of scripts
                {
                    (newScripts, updaterLogs) = await updater.UpdateScriptsAsync(targetScripts, true);

                    Logger.SystemWrite(updaterLogs);
                }
                else
                {
                    (newScript, updaterLog) = await updater.UpdateScriptAsync(targetScript, true);

                    Logger.SystemWrite(updaterLog);
                }

                watch.Stop();
                TimeSpan t = watch.Elapsed;
                Model.StatusBarText = $"Updated {targetScript.Title} ({t:h\\:mm\\:ss})";
            }
            finally
            {
                // Turn off progress ring
                Model.BuildScriptFullProgressVisibility = Visibility.Visible;
                Model.WorkInProgress = false;

                // Build Ended, Switch to Normal View
                Model.SwitchNormalBuildInterface = true;
                Model.DisplayScript(Model.CurMainTree.Script);
            }

            // Report results
            if (updateMultipleScript)
            { // Updated multiple scripts
                PackIconMaterialKind msgBoxIcon = PackIconMaterialKind.Information;
                StringBuilder        b          = new StringBuilder(updaterLogs.Length + 6);
                if (0 < newScripts.Length)
                {
                    b.AppendLine($"Successfully updated [{newScripts.Length}] scripts");
                }

                foreach (Script newSc in newScripts)
                {
                    ProjectTreeItemModel node = Model.CurMainTree.FindScriptByRealPath(newSc.RealPath);
                    Debug.Assert(node != null, "Internal error with MainTree management");
                    Model.PostRefreshScript(node, newSc);

                    b.AppendLine($"- {newSc.Title}");
                }

                LogInfo[] errorLogs = updaterLogs.Where(x => x.State == LogState.Error).ToArray();
                if (0 < errorLogs.Length)
                { // Failure
                    if (0 < newScripts.Length)
                    {
                        b.AppendLine();
                    }
                    b.AppendLine($"Failed to update [{targetScripts.Length - newScripts.Length}] scripts");
                    foreach (LogInfo log in errorLogs)
                    {
                        b.AppendLine($"- {log.Message}");
                    }

                    msgBoxIcon = PackIconMaterialKind.Alert;
                }

                const string   msgTitle = "Script Update Report";
                TextViewDialog dialog   = new TextViewDialog(this, msgTitle, msgTitle, b.ToString(), msgBoxIcon);
                dialog.ShowDialog();
            }
            else
            {     // Updated single script
                if (newScript != null)
                { // Success
                    ProjectTreeItemModel node = Model.CurMainTree.FindScriptByRealPath(newScript.RealPath);
                    Debug.Assert(node != null, "Internal error with MainTree management");
                    Model.PostRefreshScript(node, newScript);

                    MessageBox.Show(this, $"Successfully updated script {newScript.Title}",
                                    "Script Update Success",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Information);
                }
                else
                { // Failure
                    StringBuilder b = new StringBuilder(updaterLogs.Length + 6);

                    LogInfo[] errorLogs = updaterLogs.Where(x => x.State == LogState.Error).ToArray();
                    foreach (LogInfo log in errorLogs)
                    {
                        b.AppendLine($"- {log.Message}");
                    }

                    MessageBox.Show(this, b.ToString(), "Script Update Failure", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
示例#27
0
        internal static MenuItem CreateSelectAssetButton(Type assetType, Action <GameAsset> action, string key, PackIconMaterialKind icon, params AssetFilter[] filters)
        {
            MenuItem b = new MenuItem()
            {
                Header = LocalizationManager.Current.Interface[key]
            };

            b.Click += (object sender, RoutedEventArgs e) =>
            {
                AssetPicker_Window apw = new AssetPicker_Window(assetType, filters);
                apw.Owner = MainWindow.Instance;
                if (apw.ShowDialog() == true)
                {
                    action.Invoke(apw.SelectedAsset);
                }
            };
            b.Icon = new PackIconMaterial()
            {
                Kind = icon
            };
            (b.Icon as PackIconMaterial).SetResourceReference(PackIconMaterial.ForegroundProperty, "AccentColor");
            return(b);
        }
 public MaterialExtension(PackIconMaterialKind kind)
 {
     this.Kind = kind;
 }
示例#29
0
 public MaterialIcon(PackIconMaterialKind kind)
 {
     Kind = kind;
 }