public void ArrayTest()
        {
            var comparer = new AlphaNumericComparer <string>();
            var sorted   = TestArray.OrderBy(x => x, comparer).ToArray();

            Assert.AreEqual(ExpectedArray, sorted);
        }
Beispiel #2
0
        public void CompareTwoValues_ResultOrderMustBeSorted(
            string valueA,
            string valueB,
            int cmpResult
            )
        {
            // Arrange
            var testSubject = new AlphaNumericComparer();

            // Act
            int result = testSubject.Compare(valueA, valueB);

            // Assert
            _ = result.Should().Be(cmpResult, null);
        }
Beispiel #3
0
        private void InitializeEventManager()
        {
            // Subscribe to events;
            EventManager.Instance().EventAdd += (evChain) =>
            {
                EventChain_CreateItem(evChain);
            };
            EventManager.Instance().EventRemove += (evChain) =>
            {
            };
            EventManager.Instance().EventListLoad += (evChains) =>
            {
                evChains.Sort((a, b) => { return(AlphaNumericComparer.Compare(a.Name, b.Name)); });

                foreach (var evChain in evChains)
                {
                    EventChain_CreateItem(evChain);
                }
            };

            // Initialization;
            EventManager.Instance().LoadEvents();
        }
        private void SaveBtn_Click(object sender, EventArgs e)
        {
            var appData = CacheData.FindAppData(appsBox.SelectedItem.ToString());

            if (appData != default)
            {
                if (string.IsNullOrWhiteSpace(fileTypes.Text))
                {
                    appData.Settings.FileTypes = default;
                }
                else
                {
                    if (e == EventArgs.Empty || !FileTypesConflict())
                    {
                        var typesList = new List <string>();
                        foreach (var item in $"{fileTypes.Text},".Split(','))
                        {
                            if (string.IsNullOrWhiteSpace(item))
                            {
                                continue;
                            }
                            var type = new string(item.ToCharArray().Where(c => !Path.GetInvalidFileNameChars().Contains(c) && !char.IsWhiteSpace(c)).ToArray());
                            if (string.IsNullOrWhiteSpace(type) || type.Length < 1)
                            {
                                continue;
                            }
                            if (type.StartsWith(".", StringComparison.Ordinal))
                            {
                                while (type.Contains(".."))
                                {
                                    type = type.Replace("..", ".");
                                }
                                if (typesList.ContainsItem(type) || typesList.ContainsItem(type.Substring(1)))
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                if (typesList.ContainsItem(type) || typesList.ContainsItem($".{type}"))
                                {
                                    continue;
                                }
                            }
                            if (type.Length == 1 && type.StartsWith(".", StringComparison.Ordinal))
                            {
                                continue;
                            }
                            typesList.Add(type);
                        }
                        if (typesList.Any())
                        {
                            var comparer = new AlphaNumericComparer <string>();
                            typesList                  = typesList.OrderBy(x => x, comparer).ToList();
                            fileTypes.Text             = typesList.Join(",");
                            appData.Settings.FileTypes = new Collection <string>(typesList);
                        }
                    }
                    else
                    {
                        fileTypes.Text = appData.Settings.FileTypes.Join(',');
                    }
                }

                appData.Settings.StartArgsFirst = startArgsFirst.Text;
                appData.Settings.StartArgsLast  = startArgsLast.Text;

                appData.Settings.SortArgPaths = sortArgPathsCheck.Checked;
                appData.Settings.NoConfirm    = noConfirmCheck.Checked;
                appData.Settings.RunAsAdmin   = runAsAdminCheck.Checked;
                appData.Settings.NoUpdates    = noUpdatesCheck.Checked;
            }

            if (defBgCheck.Checked)
            {
                if (CacheData.CurrentImageBg != default)
                {
                    CacheData.CurrentImageBg = default;
                    if (Result != DialogResult.Yes)
                    {
                        Result = DialogResult.Yes;
                    }
                }
                bgLayout.SelectedIndex = 1;
            }

            Settings.Window.FadeInEffect   = (Settings.Window.FadeInEffectOptions)fadeInCombo.SelectedIndex;
            Settings.Window.FadeInDuration = (int)fadeInNum.Value;
            Settings.Window.Opacity        = (double)opacityNum.Value;

            Settings.Window.BackgroundImageLayout = (ImageLayout)bgLayout.SelectedIndex;

            Settings.Window.Colors.Base        = mainColorPanel.BackColor;
            Settings.Window.Colors.Control     = controlColorPanel.BackColor;
            Settings.Window.Colors.ControlText = controlTextColorPanel.BackColor;
            Settings.Window.Colors.Button      = btnColorPanel.BackColor;
            Settings.Window.Colors.ButtonHover = btnHoverColorPanel.BackColor;
            Settings.Window.Colors.ButtonText  = btnTextColorPanel.BackColor;

            Settings.Window.HideHScrollBar = hScrollBarCheck.Checked;
            Settings.Window.LargeImages    = showLargeImagesCheck.Checked;

            var dirList = new List <string>();

            if (!string.IsNullOrWhiteSpace(appDirs.Text))
            {
                var tmpDir = appDirs.Text + Environment.NewLine;
                foreach (var item in tmpDir.SplitNewLine())
                {
                    if (string.IsNullOrWhiteSpace(item))
                    {
                        continue;
                    }
                    var dir = PathEx.Combine(item);
                    try
                    {
                        if (!Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }
                        dir = EnvironmentEx.GetVariableWithPath(dir);
                        if (!dirList.ContainsItem(dir))
                        {
                            dirList.Add(dir);
                        }
                    }
                    catch (Exception ex) when(ex.IsCaught())
                    {
                        Log.Write(ex);
                    }
                }
                if (dirList.Count > 0)
                {
                    dirList.Sort();
                    appDirs.Text = dirList.Join(Environment.NewLine);
                }
            }
            Settings.AppDirs = dirList.ToArray();

            Settings.StartMenuIntegration = startMenuIntegration.SelectedIndex > 0;
            if (!Settings.StartMenuIntegration)
            {
                try
                {
                    var shortcutDirs = new[]
                    {
                        Environment.GetFolderPath(Environment.SpecialFolder.SendTo),
                        PathEx.Combine(Environment.SpecialFolder.StartMenu, "Programs")
                    };
                    foreach (var dir in shortcutDirs)
                    {
                        var shortcuts = Directory.GetFiles(dir, "Apps Launcher*.lnk", SearchOption.TopDirectoryOnly);
                        foreach (var shortcut in shortcuts.Where(File.Exists))
                        {
                            File.Delete(shortcut);
                        }
                    }
                    var startMenuDir = Path.Combine(shortcutDirs.Last(), "Portable Apps");
                    if (Directory.Exists(startMenuDir))
                    {
                        Directory.Delete(startMenuDir, true);
                    }
                }
                catch (Exception ex) when(ex.IsCaught())
                {
                    Log.Write(ex);
                }
            }

            Settings.Window.DefaultPosition = defaultPos.SelectedIndex;

            Settings.UpdateCheck   = (Settings.UpdateCheckOptions)updateCheck.SelectedIndex;
            Settings.UpdateChannel = (Settings.UpdateChannelOptions)updateChannel.SelectedIndex;

            var lang = setLang.SelectedItem.ToString();

            if (!Settings.Language.EqualsEx(lang))
            {
                if (Result != DialogResult.Yes)
                {
                    Result = DialogResult.Yes;
                }
                Settings.Language = lang;
                LoadSettings();
            }

            Settings.WriteToFile();

            MessageBoxEx.Show(this, Language.GetText(nameof(en_US.SavedSettings)), MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
        }
        public SettingsForm(LocalAppData appData)
        {
            SelectedAppData = appData;

            InitializeComponent();

            SuspendLayout();

            Icon = CacheData.GetSystemIcon(ImageResourceSymbol.SystemControl);

            foreach (TabPage tab in tabCtrl.TabPages)
            {
                tab.BackColor = Settings.Window.Colors.BaseDark;
            }

            locationBtn.BackgroundImage = CacheData.GetSystemImage(ImageResourceSymbol.Directory);
            fileTypes.AutoVerticalScrollBar();
            fileTypes.MaxLength = short.MaxValue;
            fileTypesMenu.EnableAnimation();
            fileTypesMenu.SetFixedSingle();
            associateBtn.Image = CacheData.GetSystemImage(ImageResourceSymbol.Uac);
            try
            {
                restoreFileTypesBtn.Image = new Bitmap(28, 16);
                using (var g = Graphics.FromImage(restoreFileTypesBtn.Image))
                {
                    g.DrawImage(CacheData.GetSystemImage(ImageResourceSymbol.Uac), 0, 0);
                    g.DrawImage(CacheData.GetSystemImage(ImageResourceSymbol.Undo), 12, 0);
                }
            }
            catch (Exception ex) when(ex.IsCaught())
            {
                restoreFileTypesBtn.Image      = CacheData.GetSystemImage(ImageResourceSymbol.Uac);
                restoreFileTypesBtn.ImageAlign = ContentAlignment.MiddleLeft;
                restoreFileTypesBtn.Text       = Resources.LeftArrow;
                if (restoreFileTypesBtn.Image != null)
                {
                    restoreFileTypesBtn.TextAlign = ContentAlignment.MiddleRight;
                }
            }

            previewBg.BackColor = Settings.Window.Colors.BaseDark;
            if (Settings.Window.BackgroundImage != default)
            {
                var width  = (int)Math.Round(Settings.Window.BackgroundImage.Width * .65d) + 1;
                var height = (int)Math.Round(Settings.Window.BackgroundImage.Height * .65d) + 1;
                previewBg.BackgroundImage       = Settings.Window.BackgroundImage.Redraw(width, height);
                previewBg.BackgroundImageLayout = Settings.Window.BackgroundImageLayout;
                previewLogoBox.BackColor        = Color.Transparent;
            }
            previewLogoBox.Image = Resources.Logo128px.Redraw(previewLogoBox.Height, previewLogoBox.Height);
            var exeImage = CacheData.GetSystemImage(ImageResourceSymbol.Application);

            if (exeImage != null)
            {
                previewSmallImgList.Images.Add(exeImage);
                previewSmallImgList.Images.Add(exeImage);
            }
            exeImage = CacheData.GetSystemImage(ImageResourceSymbol.Application, true);
            if (exeImage != null)
            {
                previewLargeImgList.Images.Add(exeImage);
                previewLargeImgList.Images.Add(exeImage);
            }
            previewAppList.StateImageList = Settings.Window.LargeImages ? previewLargeImgList : previewSmallImgList;
            previewAppList.View           = Settings.Window.LargeImages ? View.Tile : View.List;

            foreach (var btn in new[] { saveBtn, exitBtn })
            {
                btn.BackColor = Settings.Window.Colors.Button;
                btn.ForeColor = Settings.Window.Colors.ButtonText;
                btn.FlatAppearance.MouseDownBackColor = Settings.Window.Colors.Button;
                btn.FlatAppearance.MouseOverBackColor = Settings.Window.Colors.ButtonHover;
            }

            var comparer = new AlphaNumericComparer <object>();
            var appNames = CacheData.CurrentAppInfo.Select(x => x.Name).Cast <object>().OrderBy(x => x, comparer).ToArray();

            appsBox.Items.AddRange(appNames);

            appsBox.SelectedItem = SelectedAppData?.Name;
            if (appsBox.SelectedIndex < 0)
            {
                appsBox.SelectedIndex = 0;
            }

            appDirs.AutoVerticalScrollBar();
            addToShellBtn.Image  = CacheData.GetSystemImage(ImageResourceSymbol.Uac);
            rmFromShellBtn.Image = CacheData.GetSystemImage(ImageResourceSymbol.Uac);

            ResumeLayout(false);
        }