예제 #1
0
        void EditDomainAsset(Object testAsset, StringCryptographer decrypter, out string testResult, out MessageType testResultType)
        {
            // Setup variables
            AssetBundle bundle = null;

            testResult     = TestErrorInvalidFileMessage;
            testResultType = MessageType.Error;

            // Null check
            if (testAsset == null)
            {
                // Don't do anything if asset is null
                return;
            }

            try
            {
                // Check if we can get the path of the asset
                string localAssetPath = AssetDatabase.GetAssetPath(testAsset);

                // Load the bundle, and convert it to a domain list
                bundle = AssetBundle.LoadFromFile(localAssetPath);
                DomainList domainList = Utility.GetDomainList(bundle);

                // By default, indicate the bundle doesn't contain DomainList
                testResult     = TestErrorInvalidAssetMessage;
                testResultType = MessageType.Error;

                // Check if the bundle contains an AcceptedDomainList
                if (domainList != null)
                {
                    // By default, indicate the domain list is empty
                    testResult     = TestEmptyWarningMessage;
                    testResultType = MessageType.Warning;
                    if ((domainList != null) && (domainList.Count > 0))
                    {
                        // Replace the name of file
                        nameOfFile = Path.GetFileName(localAssetPath);

                        // Replace the name of folder
                        int stringLengthOfFolder = (localAssetPath.Length - (nameOfFile.Length + 1));
                        nameOfFolder = localAssetPath.Substring(0, stringLengthOfFolder);

                        // Replace the domain list
                        DomainList.Decrypt(domainList, decrypter, allDomains);

                        testResult     = EditMessage;
                        testResultType = MessageType.Info;
                    }
                }
            }
            finally
            {
                if (bundle != null)
                {
                    // Clean-up
                    bundle.Unload(true);
                }
            }
        }
        public override void OnInspectorGUI()
        {
            // Update the serialized object
            serializedObject.Update();

            // Display all fields
            EditorGUILayout.PropertyField(passwordHash);
            EditorGUILayout.PropertyField(saltKey);
            EditorGUILayout.PropertyField(viKey);

            // Display a button to randomize all fields
            EditorGUILayout.Space();
            if (GUILayout.Button("Randomize all fields") == true)
            {
                passwordHash.stringValue = StringCryptographer.GetRandomPassword(RandomPasswordLength);
                saltKey.stringValue      = StringCryptographer.GetRandomPassword(RandomPasswordLength);
                viKey.stringValue        = StringCryptographer.GetRandomPassword(StringCryptographer.ViKeyBlockSize);
            }

            // Display test encryption
            EditorGUILayout.Space();
            EditorUiUtility.DrawBoldFoldout(encryptionGroup, "Test Encryption");
            using (EditorGUILayout.FadeGroupScope scope = new EditorGUILayout.FadeGroupScope(encryptionGroup.faded))
            {
                if (scope.visible == true)
                {
                    testEncryption = EditorGUILayout.DelayedTextField("Input", testEncryption);
                    string output = null;
                    if (string.IsNullOrEmpty(testEncryption) == false)
                    {
                        output = ((StringCryptographer)target).Encrypt(testEncryption);
                    }
                    EditorGUILayout.TextField("Output", output);
                }
            }

            // Display test decryption
            EditorGUILayout.Space();
            EditorUiUtility.DrawBoldFoldout(decryptionGroup, "Test Decryption");
            using (EditorGUILayout.FadeGroupScope scope = new EditorGUILayout.FadeGroupScope(decryptionGroup.faded))
            {
                if (scope.visible == true)
                {
                    testDecryption = EditorGUILayout.DelayedTextField("Input", testDecryption);
                    string output = null;
                    if (string.IsNullOrEmpty(testDecryption) == false)
                    {
                        output = ((StringCryptographer)target).Decrypt(testDecryption);
                    }
                    EditorGUILayout.TextField("Output", output);
                }
            }

            // Apply modifications
            serializedObject.ApplyModifiedProperties();
        }
예제 #3
0
 static string[] ConvertToDomainList(DomainList domainList, StringCryptographer decrypter)
 {
     string[] returnDomainList = null;
     if ((domainList != null) && (domainList.Count > 0))
     {
         // Create a new string array
         returnDomainList = DomainList.Decrypt(domainList, decrypter);
     }
     return(returnDomainList);
 }
        private static void CreateSupportedLanguages()
        {
            // Setup asset
            StringCryptographer newAsset = CreateInstance <StringCryptographer>();

            // Automatically fill out the fields
            newAsset.PasswordHash = StringCryptographer.GetRandomPassword(RandomPasswordLength);
            newAsset.SaltKey      = StringCryptographer.GetRandomPassword(RandomPasswordLength);
            newAsset.ViKey        = StringCryptographer.GetRandomPassword(StringCryptographer.ViKeyBlockSize);

            // Setup path to file
            string folderName  = AssetUtility.GetSelectedFolder();
            string pathOfAsset = Path.Combine(folderName, DefaultFileName);

            pathOfAsset = AssetDatabase.GenerateUniqueAssetPath(pathOfAsset);

            // Create the asset, and prompt the user to rename it
            ProjectWindowUtil.CreateAsset(newAsset, pathOfAsset);
        }
예제 #5
0
        void OnGUI()
        {
            // Explain what this dialog does
            EditorGUILayout.HelpBox(HelpMessage, MessageType.None);

            // Draw the encrypter
            EditorGUILayout.Space();
            encrypter = (StringCryptographer)EditorGUILayout.ObjectField("Encrypter", encrypter, typeof(StringCryptographer), false);
            EditorGUILayout.Space();

            // Draw the area for testing an asset bundle
            DrawTestAssetArea();

            // Put a space between generated and test area
            EditorGUILayout.Space();

            // Draw the area for generating Domain List Assets
            DrawGenerateAssetArea();
        }
예제 #6
0
        public static DomainList GenerateDomainList(string nameOfFolder, string nameOfFile, IList <string> allDomains, StringCryptographer encrypter, bool relativeToProject = true, bool overwriteFile = false)
        {
            DomainList newAsset = DomainList.Generate(nameOfFile, allDomains, encrypter);

            // Generate the asset bundle
            AssetUtility.SaveAsAssetBundle(newAsset, nameOfFolder, nameOfFile, BundleId, new StringBuilder(), relativeToProject, overwriteFile);
            return(newAsset);
        }
예제 #7
0
        static void TestDomainAsset(Object testAsset, StringBuilder builder, StringCryptographer decrypter, out string testResult, out MessageType testResultType)
        {
            // Setup variables
            AssetBundle bundle = null;

            testResult     = TestErrorInvalidFileMessage;
            testResultType = MessageType.Error;

            // Null check
            if (testAsset == null)
            {
                // Don't do anything if asset is null
                return;
            }

            try
            {
                // Load the bundle, and convert it to a domain list
                bundle = AssetBundle.LoadFromFile(AssetDatabase.GetAssetPath(testAsset));
                DomainList domainList = Utility.GetDomainList(bundle);

                // By default, indicate the bundle doesn't contain DomainList
                testResult     = TestErrorInvalidAssetMessage;
                testResultType = MessageType.Error;

                // Check if the bundle contains an AcceptedDomainList
                if (domainList != null)
                {
                    // By default, indicate the domain list is empty
                    testResult     = TestEmptyWarningMessage;
                    testResultType = MessageType.Warning;
                    if ((domainList != null) && (domainList.Count > 0))
                    {
                        // list out all the domains in the list
                        builder.Clear();
                        builder.Append(TestInfoMessage);
                        for (int index = 0; index < domainList.Count; ++index)
                        {
                            builder.AppendLine();
                            builder.Append("* \"");
                            if (decrypter != null)
                            {
                                builder.Append(decrypter.Decrypt(domainList[index]));
                            }
                            else
                            {
                                builder.Append(domainList[index]);
                            }
                            builder.Append("\"");
                        }
                        testResult     = builder.ToString();
                        testResultType = MessageType.Info;
                    }
                }
            }
            finally
            {
                if (bundle != null)
                {
                    // Clean-up
                    bundle.Unload(true);
                }
            }
        }