Пример #1
0
 static bool CheckValidMeshWithMessageBox(Component_Mesh mesh)
 {
     if (!CommonFunctions.CheckValidMesh(mesh, out string error))
     {
         EditorMessageBox.ShowWarning(error);
         return(false);
     }
     return(true);
 }
Пример #2
0
        /////////////////////////////////////////

        public static void CheckToRemoveNotExistsFilesFromProject()
        {
            var notExists = new ESet <string>();

            foreach (var path in GetProjectFileCSFiles(false, true))
            {
                if (!File.Exists(path))
                {
                    notExists.AddWithCheckAlreadyContained(path);
                }
            }

            if (notExists.Count != 0)
            {
                var text    = EditorLocalization.Translate("General", "Unable to compile Project.csproj. The project contains files which are not exists. Remove these files from the project?") + "\r\n";
                int counter = 0;
                foreach (var fullPath in notExists)
                {
                    if (counter > 20)
                    {
                        text += "\r\n...";
                        break;
                    }

                    var path = fullPath.Replace(ProjectDir + Path.DirectorySeparatorChar, "");
                    text += "\r\n" + path;
                    counter++;
                }

                if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.YesNo) == EDialogResult.Yes)
                {
                    if (UpdateProjectFile(null, notExists, out var error))
                    {
                        if (notExists.Count > 1)
                        {
                            Log.Info(EditorLocalization.Translate("General", "Items have been removed from the Project.csproj."));
                        }
                        else
                        {
                            Log.Info(EditorLocalization.Translate("General", "The item has been removed from the Project.csproj."));
                        }
                    }
                    else
                    {
                        Log.Warning(error);
                    }
                }
            }
        }
Пример #3
0
        public static void SetCurrentLicense(string email, string password)
        {
#if !DEPLOY
            try
            {
                var key = Registry.CurrentUser.CreateSubKey(registryPath);

                key.SetValue("LoginEmail", email);
                key.SetValue("LoginHash", EncryptDecrypt(password));
                key.Close();
            }
            catch (Exception e)
            {
                EditorMessageBox.ShowWarning(e.Message);
                return;
            }

            RequestFullLicenseInfo();
#endif
        }
Пример #4
0
        public bool BuildArchive()        //string writeToDirectory )
        {
            var destFileName = Path.Combine(writeToDirectory, GetIdentifier() + "-" + GetVersion() + ".neoaxispackage");

            //check file already exists
            if (File.Exists(destFileName))
            {
                var text = $"The file with name \'{destFileName}\' is already exists. Overwrite?";
                if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.OKCancel) == EDialogResult.Cancel)
                {
                    return(false);
                }
            }

            try
            {
                var sourceDirectory = Path.GetDirectoryName(VirtualPathUtility.GetRealPathByVirtual(ComponentUtility.GetOwnedFileNameOfComponent(this)));

                //make zip

                if (File.Exists(destFileName))
                {
                    File.Delete(destFileName);
                }

                //prepare Package.info
                var packageInfoTempFileName = Path.GetTempFileName();
                {
                    var block = new TextBlock();

                    block.SetAttribute("Identifier", GetIdentifier());
                    block.SetAttribute("Title", Title.Value);

                    block.SetAttribute("Version", GetVersion());

                    //!!!!
                    block.SetAttribute("Author", "Share CC Attribution");

                    block.SetAttribute("Description", ShortDescription);
                    //"ShortDescription"

                    block.SetAttribute("FullDescription", FullDescription.Value);

                    string license = "";
                    switch (License.Value)
                    {
                    case LicenseEnum.MIT: license = "MIT"; break;

                    case LicenseEnum.CCAttribution: license = "CC Attribution"; break;

                    case LicenseEnum.FreeToUse: license = "Free To Use"; break;

                    case LicenseEnum.PaidPerSeat: license = "Paid Per Seat"; break;
                    }
                    block.SetAttribute("License", license);

                    if (License.Value == LicenseEnum.PaidPerSeat)
                    {
                        block.SetAttribute("Cost", Cost.Value.ToString());
                    }

                    {
                        var s = "";
                        foreach (CategoryEnum flag in GetFlags(Categories.Value))
                        {
                            if (flag != 0)
                            {
                                if (s.Length != 0)
                                {
                                    s += ", ";
                                }
                                s += TypeUtility.DisplayNameAddSpaces(flag.ToString());
                            }
                        }
                        block.SetAttribute("Categories", s);
                    }

                    block.SetAttribute("Tags", Tags.Value);

                    //!!!!
                    var openAfterInstall = sourceDirectory.Substring(VirtualFileSystem.Directories.Assets.Length + 1);
                    block.SetAttribute("OpenAfterInstall", openAfterInstall);

                    //MustRestart = True
                    //AddCSharpFilesToProject = "Store\\Simple Level Generator"

                    File.WriteAllText(packageInfoTempFileName, block.DumpToString());
                }

                string[] files;

                using (var archive = ZipFile.Open(destFileName, ZipArchiveMode.Create))
                {
                    files = Directory.GetFiles(sourceDirectory, "*", SearchOption.AllDirectories);
                    foreach (var file in files)
                    {
                        if (Path.GetExtension(file) == ".store")
                        {
                            continue;
                        }

                        var entryName = file.Substring(VirtualFileSystem.Directories.Project.Length + 1);
                        //var entryName = file.Substring( sourceDirectory.Length + 1 );
                        archive.CreateEntryFromFile(file, entryName);
                    }

                    archive.CreateEntryFromFile(packageInfoTempFileName, "Package.info");
                }

                if (File.Exists(packageInfoTempFileName))
                {
                    File.Delete(packageInfoTempFileName);
                }


                //write info json
                {
                    var jsonFileName = destFileName + ".json";

                    var sw = new StringWriter();
                    using (JsonWriter writer = new JsonTextWriter(sw))
                    {
                        writer.Formatting = Formatting.Indented;
                        writer.WriteStartObject();

                        writer.WritePropertyName("Author");

                        //!!!!
                        //writer.WriteValue( "3" );
                        writer.WriteValue("Share CC Attribution");


                        writer.WritePropertyName("Identifier");
                        writer.WriteValue(GetIdentifier());

                        writer.WritePropertyName("Title");
                        writer.WriteValue(Title.Value);

                        writer.WritePropertyName("License");
                        switch (License.Value)
                        {
                        case LicenseEnum.MIT: writer.WriteValue("MIT"); break;

                        case LicenseEnum.CCAttribution: writer.WriteValue("CC Attribution"); break;

                        case LicenseEnum.FreeToUse: writer.WriteValue("Free To Use"); break;

                        case LicenseEnum.PaidPerSeat: writer.WriteValue("Paid Per Seat"); break;
                        }
                        //writer.WriteValue( License.Value.ToString() );

                        writer.WritePropertyName("Cost");
                        writer.WriteValue(Cost.Value.ToString());

                        writer.WritePropertyName("ShortDescription");
                        writer.WriteValue(ShortDescription.Value);

                        writer.WritePropertyName("FullDescription");
                        writer.WriteValue(FullDescription.Value);

                        {
                            writer.WritePropertyName("Categories");

                            var s = "";
                            foreach (CategoryEnum flag in GetFlags(Categories.Value))
                            {
                                if (flag != 0)
                                {
                                    if (s.Length != 0)
                                    {
                                        s += ", ";
                                    }
                                    s += TypeUtility.DisplayNameAddSpaces(flag.ToString());
                                }
                            }
                            writer.WriteValue(s);

                            //writer.WriteValue( Categories.Value.ToString() );
                        }

                        writer.WritePropertyName("Tags");
                        writer.WriteValue(Tags.Value);

                        writer.WritePropertyName("Version");
                        writer.WriteValue(GetVersion());

                        //writer.WriteEnd();
                        writer.WriteEndObject();
                    }

                    File.WriteAllText(jsonFileName, sw.ToString());
                }

                //try to create screenshots
                if (CreateScreenshots)
                {
                    //find in the folder one import file (FBX, etc). make screenshot of 'Mesh' object inside the import file.

                    var resourceType     = ResourceManager.GetTypeByName("Import 3D");
                    var importExtensions = new ESet <string>();
                    foreach (var e in resourceType.FileExtensions)
                    {
                        importExtensions.AddWithCheckAlreadyContained("." + e);
                    }

                    var importVirtualFileNames = new List <string>();
                    foreach (var file in files)
                    {
                        var ext = Path.GetExtension(file);
                        if (!string.IsNullOrEmpty(ext) && importExtensions.Contains(ext))
                        {
                            var virtualFileName = VirtualPathUtility.GetVirtualPathByReal(file);
                            if (!string.IsNullOrEmpty(virtualFileName))
                            {
                                importVirtualFileNames.Add(virtualFileName);
                            }
                        }
                    }

                    if (importVirtualFileNames.Count == 1)
                    {
                        var import3D = ResourceManager.LoadResource <Component_Import3D>(importVirtualFileNames[0]);
                        if (import3D != null)
                        {
                            var mesh = import3D.GetComponent <Component_Mesh>("Mesh");
                            if (mesh != null)
                            {
                                var generator = new MeshImageGenerator();
                                generator.Generate(mesh, destFileName + ".logo.png");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                EditorMessageBox.ShowWarning(e.Message);
                return(false);
            }

            return(true);
        }
Пример #5
0
            public override bool Creation(NewObjectCell.ObjectCreationContext context)
            {
                if (Window.IsFileCreation())
                {
                    context.disableFileCreation = true;

                    GetCreateCSharpClassInfo(out var csharpRealFileName, out var csharpClassName, out var csharpClassNameWithoutNamespace);

                    try
                    {
                        //main file
                        {
                            string name       = Template.Name + ".scene";
                            var    sourceFile = VirtualPathUtility.GetRealPathByVirtual(@"Base\Tools\NewResourceTemplates\" + name);

                            //copy scene file

                            var text = File.ReadAllText(sourceFile);

                            if (CreateCSharpClass)
                            {
                                text = text.Replace(".component NeoAxis.Component_Scene", ".component " + csharpClassName);
                            }

                            File.WriteAllText(context.fileCreationRealFileName, text);

                            //copy additional folder if exist
                            var sourceFolderPath = sourceFile + "_Files";
                            if (Directory.Exists(sourceFolderPath))
                            {
                                var destFolderPath = context.fileCreationRealFileName + "_Files";
                                IOUtility.CopyDirectory(sourceFolderPath, destFolderPath);
                            }
                        }

                        //cs file
                        if (CreateCSharpClass)
                        {
                            string code = @"using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using NeoAxis;

namespace Project
{
	public class {Name} : {Base}
	{
	}
}";

                            code = code.Replace("{Name}", csharpClassNameWithoutNamespace);
                            code = code.Replace("{Base}", Window.SelectedType.Name);

                            File.WriteAllText(csharpRealFileName, code);
                        }
                    }
                    catch (Exception e)
                    {
                        EditorMessageBox.ShowWarning(e.Message);
                        //Log.Warning( e.Message );
                        return(false);
                    }

                    if (CreateCSharpClass)
                    {
                        //add to Project.csproj
                        {
                            var toAdd = new List <string>();

                            var fileName = Path.Combine("Assets", VirtualPathUtility.GetVirtualPathByReal(csharpRealFileName));
                            toAdd.Add(fileName);

                            if (CSharpProjectFileUtility.UpdateProjectFile(toAdd, null, out var error))
                            {
                                if (toAdd.Count > 1)
                                {
                                    Log.Info(EditorLocalization.Translate("General", "Items have been added to the Project.csproj."));
                                }
                                else
                                {
                                    Log.Info(EditorLocalization.Translate("General", "The item has been added to the Project.csproj."));
                                }
                            }
                            else
                            {
                                EditorMessageBox.ShowWarning(error);
                                //Log.Warning( error );
                                return(false);
                            }
                        }

                        Window.DisableUnableToCreateReason = true;

                        //restart application
                        var text = EditorLocalization.Translate("General", "To apply changes need restart the editor. Restart?\r\n\r\nThe editor must be restarted to compile and enable a new created C# class.");
                        if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.YesNo) == EDialogResult.Yes)
                        {
                            EditorAPI.BeginRestartApplication();
                        }

                        Window.DisableUnableToCreateReason = false;
                    }
                }

                return(true);
            }
        public override void Register()
        {
            //Upload to the Store
            {
                var a = new EditorAction();
                //!!!!
                a.Name = "Prepare for the Store";
                //a.Name = "Upload to the Store";
                a.Description        = "Uploads the selected product or all products in the selected folder to the NeoAxis Store.";
                a.CommonType         = EditorAction.CommonTypeEnum.General;
                a.ImageSmall         = Properties.Resources.Package_16;
                a.ImageBig           = Properties.Resources.Package_32;
                a.QatSupport         = true;
                a.ContextMenuSupport = EditorContextMenuWinForms.MenuTypeEnum.Resources;
                a.RibbonText         = ("Upload", "");

                a.GetState += delegate(EditorAction.GetStateContext context)
                {
                    if (context.ObjectsInFocus.DocumentWindow == null && context.ObjectsInFocus.Objects.Length != 0)
                    {
                        var fileItems = context.ObjectsInFocus.Objects.OfType <ContentBrowserItem_File>();
                        foreach (var fileItem in fileItems)
                        {
                            if (fileItem.IsDirectory)
                            {
                                bool skip = false;

                                if (context.Holder == EditorAction.HolderEnum.ContextMenu)
                                {
                                    var files = Directory.GetFiles(fileItem.FullPath, "*.store", SearchOption.AllDirectories);
                                    if (files.Length == 0)
                                    {
                                        skip = true;
                                    }
                                }

                                if (!skip)
                                {
                                    context.Enabled = true;
                                    break;
                                }
                            }

                            if (!fileItem.IsDirectory && Path.GetExtension(fileItem.FullPath).ToLower() == ".store")
                            {
                                context.Enabled = true;
                                break;
                            }
                        }
                    }
                };

                a.Click += delegate(EditorAction.ClickContext context)
                {
                    if (context.ObjectsInFocus.DocumentWindow == null && context.ObjectsInFocus.Objects.Length != 0)
                    {
                        var realFileNames = new ESet <string>();
                        {
                            var fileItems = context.ObjectsInFocus.Objects.OfType <ContentBrowserItem_File>();
                            foreach (var fileItem in fileItems)
                            {
                                if (fileItem.IsDirectory)
                                {
                                    realFileNames.AddRangeWithCheckAlreadyContained(Directory.GetFiles(fileItem.FullPath, "*.store", SearchOption.AllDirectories));
                                }

                                if (!fileItem.IsDirectory && Path.GetExtension(fileItem.FullPath).ToLower() == ".store")
                                {
                                    realFileNames.AddWithCheckAlreadyContained(fileItem.FullPath);
                                    break;
                                }
                            }
                        }

                        var virtualFileNames = new List <string>();
                        foreach (var realFileName in realFileNames)
                        {
                            var virtualFileName = VirtualPathUtility.GetVirtualPathByReal(realFileName);
                            if (VirtualFile.Exists(virtualFileName))
                            {
                                virtualFileNames.Add(virtualFileName);
                            }
                        }
                        if (virtualFileNames.Count == 0)
                        {
                            return;
                        }

                        var text = "Upload selected products to the store?\n\n";
                        foreach (var fileName in virtualFileNames)
                        {
                            text += fileName + "\n";
                        }
                        if (EditorMessageBox.ShowQuestion(text, EMessageBoxButtons.OKCancel) == EDialogResult.Cancel)
                        {
                            return;
                        }

                        //process
                        var item = ScreenNotifications.ShowSticky("Processing...");
                        try
                        {
                            foreach (var fileName in virtualFileNames)
                            {
                                var res = ResourceManager.LoadResource(fileName, true);
                                if (res != null)
                                {
                                    var product = res.ResultComponent as Component_StoreProduct;
                                    if (product != null)
                                    {
                                        if (!product.BuildArchive())
                                        {
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Log.Warning(e.Message);
                            return;
                        }
                        finally
                        {
                            item.Close();
                        }

                        if (virtualFileNames.Count > 1)
                        {
                            ScreenNotifications.Show("The products were prepared successfully.");
                        }
                        else
                        {
                            ScreenNotifications.Show("The product was prepared successfully.");
                        }

                        //open folder in the Explorer
                        Win32Utility.ShellExecuteEx(null, Component_StoreProduct.writeToDirectory);
                    }
                };

                EditorActions.Register(a);
            }
        }
 private void Button_Click(UIButton sender)
 {
     EditorMessageBox.ShowInfo("Editor message box.");
 }