示例#1
0
        private void LoadImagesCore(string DirectoryPath, CancellationToken CancellationToken)
        {
            this.IsLoadingFiles = true;
            try
            {
                CancellationToken.ThrowIfCancellationRequested();

                _ActiveFiles.Clear();
                this.ActiveImage = null;

                this.ZoomFit();

                System.IO.DirectoryInfo SelectedDirectory;
                try
                {
                    SelectedDirectory = new System.IO.DirectoryInfo(DirectoryPath);
                }
                catch (System.IO.IOException)
                {
                    //System.Windows.MessageBox.Show("Could not open directory: " + ex.Message);
                    return;
                }

                var NaturalStringComparer = new NaturalStringComparer();
                foreach (var FileInfo in SelectedDirectory.EnumerateFiles().OrderBy((o) => o.Name, NaturalStringComparer))
                {
                    CancellationToken.ThrowIfCancellationRequested();

                    var Decoder = ImageFileUtils.CreateDecoder(FileInfo);
                    if (Decoder == null || Decoder.Frames == null || Decoder.Frames.Count == 0 || Decoder.Frames[0].Width == 0 || Decoder.Frames[0].Height == 0)
                    {
                        continue;
                    }

                    lock (ActiveFilesLock)
                    {
                        _ActiveFiles.Add(FileInfo);
                    }
                    if (_ActiveFiles.Count == 1)
                    {
                        this.MoveToFirst();
                    }
                }
            }
            catch (OperationCanceledException)
            {
                //Ignore task cancel
                throw;
            }
            catch (Exception)
            {
                //TODO: Error handling
            }
            finally
            {
                this.IsLoadingFiles = false;
            }
        }
        public void Compare_uses_natural_sorting_when_comparing_the_two_strings()
        {
            const string left  = "Folder 10";
            const string right = "Folder 5";

            var result = new NaturalStringComparer().Compare(left, right);

            result.Should().Be(1);
        }
    /// <summary>
    /// Class constructor.  Initializes various elements
    /// </summary>
    public ListViewColumnSorter()
    {
        // Initialize the column to '0'
        ColumnToSort = 0;

        // Initialize the sort order to 'none'
        OrderOfSort = SortOrder.None;

        // Initialize the CaseInsensitiveComparer object
        ObjectCompare = new NaturalStringComparer();
    }
        public void Compare()
        {
            var nsc = new NaturalStringComparer();

            Assert.AreEqual(0, nsc.Compare(null, null));
            Assert.AreEqual(-1, nsc.Compare(null, "X"));
            Assert.AreEqual(1, nsc.Compare("X", null));
            Assert.AreEqual(0, nsc.Compare("X", "X"));
            Assert.AreEqual(-1, nsc.Compare("X", "Y"));
            Assert.AreEqual(-1, nsc.Compare("2", "10"));
            Assert.AreEqual(-1, nsc.Compare("X2", "X10"));
            Assert.AreEqual(1, nsc.Compare("X2", "X1"));
            Assert.AreEqual(-1, nsc.Compare("v1.0.2", "v1.0.10"));
            Assert.AreEqual(-1, nsc.Compare("1.2", "1.10"));
            Assert.AreEqual(-1, nsc.Compare("1 2", "1 10"));
            Assert.AreEqual(-1, nsc.Compare("1.2", "1 10"));
            Assert.AreEqual(-1, nsc.Compare("1-2", "1/10"));
        }
        public void Compare()
        {
            var comparer = new NaturalStringComparer();

            Assert.That(comparer.Compare("abc", "abc"), Is.EqualTo(0));
            Assert.That(comparer.Compare("ABC", "abc"), Is.EqualTo(0));

            Assert.That(comparer.Compare("aac", "abc"), Is.LessThan(0));
            Assert.That(comparer.Compare("abc", "aac"), Is.GreaterThan(0));

            Assert.That(comparer.Compare("acc", "abc"), Is.GreaterThan(0));
            Assert.That(comparer.Compare("abc", "acc"), Is.LessThan(0));

            Assert.That(comparer.Compare("a01", "a10"), Is.LessThan(0));
            Assert.That(comparer.Compare("a10", "a01"), Is.GreaterThan(0));

            Assert.That(comparer.Compare("a1b", "a10b"), Is.LessThan(0));
            Assert.That(comparer.Compare("a10b", "a1b"), Is.GreaterThan(0));

            Assert.That(comparer.Compare("a١b", "a١٠b"), Is.LessThan(0));
            Assert.That(comparer.Compare("a١٠b", "a١b"), Is.GreaterThan(0));
        }
        public void Compare_returns_difference_in_length_of_the_two_strings(string left, string right)
        {
            var result = new NaturalStringComparer().Compare(left, right);

            result.Should().Be(left.Length - right.Length);
        }
        private void OnGUI()
        {
            if (!_isFirstDrawn && Event.current.type == EventType.Layout)
            {
                Rect rect = position;
                rect.width  = _windowSize.x;
                rect.height = _windowSize.y;
                position    = rect;

                _isFirstDrawn = true;
            }

            Texture2D[] inputTextures =
                Selection.objects
                .OfType <Texture2D>()
                .Where(tex => tex.GetTextureImporter().spriteImportMode == SpriteImportMode.None)
                .ToArray();

            GUILayout.Space(1f);
            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.Label("Max atlas size: ", GUILayout.Width(90f));
                _atlasSize =
                    EditorGUILayout.IntPopup(
                        _atlasSize,
                        new[] { "256", "512", "1024", "2048", "4096" },
                        new[] { 256, 512, 1024, 2048, 4096 },
                        GUILayout.Width(50)
                        );

                GUILayout.Label("Padding (px): ", GUILayout.Width(80f));
                _atlasPadding = EditorGUILayout.IntSlider(_atlasPadding, 0, 10);
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal(GUILayout.Width(200f));
            {
                EditorGUILayout.HelpBox(
                    inputTextures.Length > 0 ?
                    string.Format("Selected {0} texture(s)", inputTextures.Length) :
                    "Select textures in the Project view first.",
                    MessageType.Info,
                    true);
            }
            EditorGUILayout.EndHorizontal();

            GUI.enabled = inputTextures.Length > 0;
            if (GUILayout.Button("Pack into atlas"))
            {
                string atlasPath = EditorUtility.SaveFilePanelInProject("Save atlas image", "Atlas.png", "png", "Please enter a file name to save the atlas to");
                if (!string.IsNullOrEmpty(atlasPath))
                {
                    Texture2D       atlasTexture;
                    TextureImporter atlasTextureImported;

                    NaturalStringComparer naturalStringComparer = new NaturalStringComparer();
                    List <Texture2D>      sortedInputTextures   = inputTextures.ToList();
                    sortedInputTextures.Sort((tex1, tex2) => {
                        string path1 = AssetDatabase.GetAssetPath(tex1);
                        string path2 = AssetDatabase.GetAssetPath(tex2);

                        return(naturalStringComparer.Compare(path1, path2));
                    });
                    inputTextures = sortedInputTextures.ToArray();

                    PackTextures(inputTextures, atlasPath, _atlasSize, _atlasPadding, out atlasTexture, out atlasTextureImported);
                    EditorGUIUtility.PingObject(AssetDatabase.LoadAssetAtPath(atlasPath, typeof(Texture2D)));
                    Debug.Log(string.Format("Atlas image saved to \"{0}\"", atlasPath));
                }
            }
        }
示例#8
0
 [TestCase("5.40ю", "5.040", ExpectedResult = 1)]        //Реальный кейс, падали при сравнении в IndexOutOfRangeException
 public int CompareStringsTest(string a, string b)
 {
     return(NaturalStringComparer.CompareStrings(a, b));
 }
 public int CompareStrings(string a, string b, bool ignoreWhiteSpace)
 {
     var comparer = new NaturalStringComparer(ignoreWhiteSpace);
     return comparer.Compare(a, b);
 }
        private void LoadImagesCore(string DirectoryPath, CancellationToken CancellationToken)
        {
            this.IsLoadingFiles = true;
            try
            {
                CancellationToken.ThrowIfCancellationRequested();

                _ActiveFiles.Clear();
                this.ActiveImage = null;

                this.ZoomFit();

                System.IO.DirectoryInfo SelectedDirectory;
                try
                {
                    SelectedDirectory = new System.IO.DirectoryInfo(DirectoryPath);
                }
                catch (System.IO.IOException)
                {
                    //System.Windows.MessageBox.Show("Could not open directory: " + ex.Message);
                    return;
                }

                var NaturalStringComparer = new NaturalStringComparer();
                foreach (var FileInfo in SelectedDirectory.EnumerateFiles().OrderBy((o) => o.Name, NaturalStringComparer))
                {
                    CancellationToken.ThrowIfCancellationRequested();

                    var Decoder = ImageFileUtils.CreateDecoder(FileInfo);
                    if (Decoder == null || Decoder.Frames == null || Decoder.Frames.Count == 0 || Decoder.Frames[0].Width == 0 || Decoder.Frames[0].Height == 0)
                        continue;

                    lock (ActiveFilesLock)
                    {
                        _ActiveFiles.Add(FileInfo);
                    }
                    if (_ActiveFiles.Count == 1)
                        this.MoveToFirst();
                }
            }
            catch (OperationCanceledException)
            {
                //Ignore task cancel
                throw;
            }
            catch (Exception)
            {
                //TODO: Error handling
            }
            finally
            {
                this.IsLoadingFiles = false;
            }
        }
示例#11
0
 public int CompareTo(GameFolder other)
 {
     return(NaturalStringComparer.CompareOrdinal(DirectoryInfo.FullName, other?.DirectoryInfo.FullName, ignoreCase: true));
 }
示例#12
0
 public int Compare(string x, string y)
 {
     return(NaturalStringComparer.Compare(x, y));
 }