public void CompatibilityCompressBase64FromCSharp(LZStringTestCase test)
        {
            var compress   = LZString.CompressToBase64(test.Uncompressed);
            var uncompress = RunNodeLzString("decompressFromBase64", compress);

            Console.WriteLine("c# compression result:");
            Console.WriteLine(compress);
            Assert.That(uncompress, Is.EqualTo(test.Uncompressed));
        }
        public void CompressToBase64Performance()
        {
            var value = new string('x', 65536);

            LZString.CompressToBase64(value); // Warmup

            var timer = new Stopwatch();

            timer.Start();
            const int times = 1024;

            for (var i = 0; i < times; i++)
            {
                LZString.CompressToBase64(value);
            }

            timer.Stop();
            Assert.Pass($"Did {times} compressions in {timer.Elapsed.TotalSeconds}s. Average: {timer.ElapsedMilliseconds / times}ms");
        }
示例#3
0
        private void 保存SToolStripButton_Click(object sender, EventArgs e)
        {
            if (strSaveFile == "")
            {
                if (saveFileDialog1.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                strSaveFile = saveFileDialog1.FileName;
            }
            else
            {
                File.Copy(strSaveFile, strSaveFile + ".bak");
            }
            StreamWriter wr = new StreamWriter(strSaveFile);

            wr.Write(LZString.CompressToBase64(textBoxSaveFileContent.Text));
            wr.Close();
        }
 public void CompressToBase64(LZStringTestCase test)
 {
     Assert.That(LZString.CompressToBase64(test.Uncompressed), Is.EqualTo(test.CompressedBase64));
 }
示例#5
0
        public virtual void OnGUI()
        {
            if (this.titleDataObject == null || this.serializedObject == null || this.serializedProperty == null)
            {
                GUILayout.Label("Please Re-open the editor.");
                return;
            }

            if (this.activeDataVersionIndex < 0 || this.activeDataVersionIndex >= this.titleDataObject.Versions.Count)
            {
                this.activeDataVersionIndex = this.titleDataObject.Versions.Count - 1;
            }


            using (var changeCheck = new EditorGUI.ChangeCheckScope())
            {
                using (new GUILayout.VerticalScope("box", GUILayout.ExpandWidth(true)))
                {
                    using (new GUILayout.HorizontalScope(GUILayout.ExpandWidth(true)))
                    {
                        // TitleDataKeyName
                        GUILayout.Label("TitleData Key", GUILayout.Width(80));
                        this.titleDataObject.TitleDataKeyName = GUILayout.TextField(this.titleDataObject.TitleDataKeyName, GUILayout.Width(200));
                        GUILayout.Space(10);

                        // SerializeWithUnity
                        this.titleDataObject.SerializeWithUnity = GUILayout.Toggle(this.titleDataObject.SerializeWithUnity, "Serialize With Unity", GUILayout.Width(140));

                        // CompressData
                        this.titleDataObject.CompressData = GUILayout.Toggle(this.titleDataObject.CompressData, "Compress Data", GUILayout.Width(150));

                        GUILayout.FlexibleSpace();

                        // Upload Button
                        if (GUILayout.Button("Upload", GUILayout.Width(100)))
                        {
                            string json = string.Empty;

                            if (this.titleDataObject.SerializeWithUnity)
                            {
                                json = JsonUtility.ToJson(this.titleDataObject.Data[this.activeDataVersionIndex]);
                            }
                            else
                            {
                                json = PlayFabManager.SerializerPlugin.SerializeObject(this.titleDataObject.Data[this.activeDataVersionIndex]);
                            }

                            if (this.titleDataObject.CompressData)
                            {
                                json = LZString.CompressToBase64(json);
                            }

                            string titleDataKey = string.Format("{0}_{1}", this.titleDataObject.TitleDataKeyName, this.titleDataObject.Versions[this.activeDataVersionIndex]);
                            PlayFabEditorAdmin.SetTitleDataAndPrintErrorOrSuccess(titleDataKey, json);
                        }
                    }

                    using (new GUILayout.HorizontalScope(GUILayout.ExpandWidth(true)))
                    {
                        GUILayout.Label("Version", GUILayout.Width(60));
                        this.activeDataVersionIndex = EditorGUILayout.Popup(this.activeDataVersionIndex, this.GetVersions(), GUILayout.Width(80));

                        // Drawing Add Button
                        if (ButtonUtil.DrawAddButton(new Rect(new Vector2(155, 24), new Vector2(15, 15))))
                        {
                            this.serializedObject.FindProperty("data").arraySize++;
                            this.serializedObject.FindProperty("versions").arraySize++;
                            this.serializedObject.ApplyModifiedProperties();

                            // Making sure we select the newly created version
                            this.activeDataVersionIndex = this.titleDataObject.Versions.Count - 1;
                        }

                        // Drawing Delete Button
                        if (this.titleDataObject.Versions.Count > 1)
                        {
                            if (ButtonUtil.DrawDeleteButton(new Rect(new Vector2(175, 24), new Vector2(15, 15))))
                            {
                                this.serializedObject.FindProperty("data").DeleteArrayElementAtIndex(this.activeDataVersionIndex);
                                this.serializedObject.FindProperty("versions").DeleteArrayElementAtIndex(this.activeDataVersionIndex);
                                this.serializedObject.ApplyModifiedProperties();
                                return;
                            }
                        }
                    }
                }

                using (var horizontalScope = new GUILayout.HorizontalScope("box", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
                {
                    using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(scrollBarPosition))
                    {
                        scrollBarPosition = scrollViewScope.scrollPosition;

                        EditorGUILayout.Space();

                        // Drawing the Version String
                        using (new LabelWidthScope(60))
                        {
                            string version    = this.titleDataObject.Versions[this.activeDataVersionIndex];
                            string newVersion = EditorGUILayout.TextField("Version", version);

                            if (version != newVersion)
                            {
                                this.titleDataObject.Versions[this.activeDataVersionIndex] = newVersion;
                            }
                        }

                        // Drawing everything else (user defined)
                        this.DrawData(this.titleDataObject.Data[this.activeDataVersionIndex], this.serializedObject, this.serializedProperty.GetArrayElementAtIndex(this.activeDataVersionIndex));
                    }
                }

                // Making sure we mark the data dirty if it changed
                if (changeCheck.changed)
                {
                    EditorUtility.SetDirty(this.serializedObject.targetObject);
                    this.serializedObject.ApplyModifiedProperties();
                }
            }
        }
        public virtual void OnGUI()
        {
            if (this.titleDataObject == null || this.serializedObject == null || this.serializedProperty == null)
            {
                GUILayout.Label("Please Re-open the editor.");
                return;
            }

            using (var changeCheck = new EditorGUI.ChangeCheckScope())
            {
                using (new GUILayout.HorizontalScope("box", GUILayout.ExpandWidth(true)))
                {
                    // TitleDataKeyName
                    GUILayout.Label("TitleData Key", GUILayout.Width(80));
                    this.titleDataObject.TitleDataKeyName = GUILayout.TextField(this.titleDataObject.TitleDataKeyName, GUILayout.Width(200));
                    GUILayout.Space(10);

                    // SerializeWithUnity
                    this.titleDataObject.SerializeWithUnity = GUILayout.Toggle(this.titleDataObject.SerializeWithUnity, "Serialize With Unity", GUILayout.Width(140));

                    // CompressData
                    this.titleDataObject.CompressData = GUILayout.Toggle(this.titleDataObject.CompressData, "Compress Data", GUILayout.Width(150));

                    GUILayout.FlexibleSpace();

                    // Upload Button
                    if (GUILayout.Button("Upload", GUILayout.Width(100)))
                    {
                        string json = string.Empty;

                        if (this.titleDataObject.SerializeWithUnity)
                        {
                            json = JsonUtility.ToJson(this.titleDataObject.Data);
                        }
                        else
                        {
                            json = PlayFabManager.SerializerPlugin.SerializeObject(this.titleDataObject.Data);
                        }

                        if (this.titleDataObject.CompressData)
                        {
                            json = LZString.CompressToBase64(json);
                        }

                        PlayFabEditorAdmin.SetTitleDataAndPrintErrorOrSuccess(this.titleDataObject.TitleDataKeyName, json);
                    }
                }

                using (var horizontalScope = new GUILayout.HorizontalScope("box", GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)))
                {
                    using (var scrollViewScope = new EditorGUILayout.ScrollViewScope(scrollBarPosition))
                    {
                        scrollBarPosition = scrollViewScope.scrollPosition;

                        this.DrawData(this.titleDataObject.Data, this.serializedObject, this.serializedProperty);
                    }
                }

                // Making sure we mark the data dirty if it changed
                if (changeCheck.changed)
                {
                    EditorUtility.SetDirty(this.serializedObject.targetObject);
                    this.serializedObject.ApplyModifiedProperties();
                }
            }
        }