Beispiel #1
0
        private void kryptonButtonNewCreate_Click(object sender, EventArgs e)
        {
            //!!!!

            string folder = kryptonTextBoxNewFolder.Text.Trim();

            if (string.IsNullOrEmpty(folder))
            {
                return;
            }

            try
            {
                while (Directory.Exists(folder) && !IOUtility.IsDirectoryEmpty(folder))
                {
                    var text   = string.Format(Translate("Destination folder \'{0}\' is not empty. Clear folder and continue?"), folder);
                    var result = EditorMessageBox.ShowQuestion(text, MessageBoxButtons.OKCancel);
                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }

                    IOUtility.ClearDirectory(folder);
                }

                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }

                creationInProgress             = true;
                progressBarNew.Visible         = true;
                kryptonButtonNewCancel.Visible = true;
                creationDirectory = folder;

                var tag = objectsBrowserNew.SelectedItems[0].Tag as string;
                creationTask = new Task(CreationFunction, tag);
                creationTask.Start();
            }
            catch (Exception ex)
            {
                EditorMessageBox.ShowWarning(ex.Message);
                return;
            }
        }
Beispiel #2
0
        void CreationFunction(object parameter)
        {
            var tag = (string)parameter;

            creationProgressBarValue = 0;

            try
            {
                string sourcePath = VirtualFileSystem.Directories.Project;

                FileInfo[] allFiles = new DirectoryInfo(sourcePath).GetFiles("*.*", SearchOption.AllDirectories);

                long totalLength = 0;
                foreach (var fileInfo in allFiles)
                {
                    totalLength += fileInfo.Length;
                }

                foreach (string dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories))
                {
                    if (Directory.Exists(dirPath))
                    {
                        Directory.CreateDirectory(dirPath.Replace(sourcePath, creationDirectory));
                    }
                }

                long processedLength = 0;
                foreach (var fileInfo in allFiles)
                {
                    if (File.Exists(fileInfo.FullName))
                    {
                        File.Copy(fileInfo.FullName, fileInfo.FullName.Replace(sourcePath, creationDirectory), false);
                    }

                    processedLength         += fileInfo.Length;
                    creationProgressBarValue = (int)((double)processedLength / (double)totalLength * 100.0);
                    if (creationProgressBarValue > 100)
                    {
                        creationProgressBarValue = 100;
                    }

                    if (!creationInProgress)
                    {
                        return;
                    }
                }

                //if( tag == "Clean" )
                //{
                //	var directory = Path.Combine( creationDirectory, @"Project\Data\_Dev" );
                //	EditorMessageBox.ShowInfo( directory );
                //}

                //Public build
                if (tag == "PublicBuild" || tag == "PublicBuildEmpty")
                {
                    //delete files from root of Assets
                    {
                        var dataDirectory = Path.Combine(creationDirectory, @"Assets");
                        var info          = new DirectoryInfo(dataDirectory);
                        foreach (var file in info.GetFiles())
                        {
                            file.Delete();
                        }
                    }

                    //clear User settings
                    var path = Path.Combine(creationDirectory, @"User settings");
                    if (Directory.Exists(path))
                    {
                        IOUtility.ClearDirectory(path);
                    }

                    //delete _Dev
                    {
                        path = Path.Combine(creationDirectory, @"Assets\_Dev");
                        if (Directory.Exists(path))
                        {
                            Directory.Delete(path, true);
                        }
                    }

                    //delete Caches\Files\_Dev
                    {
                        path = Path.Combine(creationDirectory, @"Caches\Files\_Dev");
                        if (Directory.Exists(path))
                        {
                            Directory.Delete(path, true);
                        }
                    }

                    //delete Binaries\NeoAxis.Internal\Localization
                    path = Path.Combine(creationDirectory, @"Binaries\NeoAxis.Internal\Localization");
                    if (Directory.Exists(path))
                    {
                        Directory.Delete(path, true);
                    }

                    if (tag == "PublicBuildEmpty")
                    {
                        //delete _Tests
                        path = Path.Combine(creationDirectory, @"Assets\_Tests");
                        if (Directory.Exists(path))
                        {
                            Directory.Delete(path, true);
                        }

                        //delete Samples\Nature Demo
                        path = Path.Combine(creationDirectory, @"Assets\Samples\Nature Demo");
                        if (Directory.Exists(path))
                        {
                            Directory.Delete(path, true);
                        }

                        //delete Samples\Sci-fi Demo
                        path = Path.Combine(creationDirectory, @"Assets\Samples\Sci-fi Demo");
                        if (Directory.Exists(path))
                        {
                            Directory.Delete(path, true);
                        }

                        ////delete Samples
                        //path = Path.Combine( creationDirectory, @"Assets\Samples" );
                        //if( Directory.Exists( path ) )
                        //	Directory.Delete( path, true );

                        //delete Caches\Files\_Tests
                        path = Path.Combine(creationDirectory, @"Caches\Files\_Tests");
                        if (Directory.Exists(path))
                        {
                            Directory.Delete(path, true);
                        }

                        //delete Caches\Files\Samples\Sci-fi Demo
                        path = Path.Combine(creationDirectory, @"Caches\Files\Samples\Sci-fi Demo");
                        if (Directory.Exists(path))
                        {
                            Directory.Delete(path, true);
                        }

                        ////delete Caches\Files
                        //path = Path.Combine( creationDirectory, @"Caches\Files" );
                        //if( Directory.Exists( path ) )
                        //	Directory.Delete( path, true );

                        //fix EditorDockingDefault.config
                        try
                        {
                            File.Copy(
                                Path.Combine(sourcePath, @"Assets\Base\Tools\EditorDockingDefault_Empty.config"),
                                Path.Combine(creationDirectory, @"Assets\Base\Tools\EditorDockingDefault.config"), true);
                        }
                        catch { }

                        ////fix Project.csproj
                        //try
                        //{
                        //	var fileName = Path.Combine( creationDirectory, "Project.csproj" );

                        //	var newLines = new List<string>();
                        //	foreach( var line in File.ReadAllLines( fileName ) )
                        //	{
                        //		if( !line.Contains( @"Assets\Samples\" ) )
                        //			newLines.Add( line );
                        //	}

                        //	File.WriteAllLines( fileName, newLines );
                        //}
                        //catch { }
                    }

                    //delete EditorDockingDefault_Empty.config
                    try
                    {
                        File.Delete(Path.Combine(creationDirectory, @"Assets\Base\Tools\EditorDockingDefault_Empty.config"));
                    }
                    catch { }

                    //delete NeoAxis.DeveloperBuild.config
                    path = Path.Combine(creationDirectory, @"NeoAxis.DeveloperBuild.config");
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }

                    //delete obj folders
                    foreach (string dirPath in Directory.GetDirectories(creationDirectory, "obj", SearchOption.AllDirectories))
                    {
                        if (Directory.Exists(dirPath))
                        {
                            Directory.Delete(dirPath, true);
                        }
                    }

                    //delete .vs folders
                    foreach (string dirPath in Directory.GetDirectories(creationDirectory, ".vs", SearchOption.AllDirectories))
                    {
                        if (Directory.Exists(dirPath))
                        {
                            Directory.Delete(dirPath, true);
                        }
                    }

                    //rewrite ProjectSettings.component
                    {
                        var content  = @".component NeoAxis.Component_ProjectSettings
{
	Name = All

	.component NeoAxis.Component_ProjectSettings_PageBasic
	{
		Name = General
	}
	.component NeoAxis.Component_ProjectSettings_PageBasic
	{
		Name = Scene Editor
	}
	.component NeoAxis.Component_ProjectSettings_PageBasic
	{
		Name = UI Editor
	}
	.component NeoAxis.Component_ProjectSettings_PageBasic
	{
		Name = C# Editor
	}
	.component NeoAxis.Component_ProjectSettings_PageBasic
	{
		Name = Shader Editor
	}
	.component NeoAxis.Component_ProjectSettings_PageBasic
	{
		Name = Text Editor
	}
	.component NeoAxis.Component_ProjectSettings_PageBasic
	{
		Name = Ribbon and Toolbar
	}
	.component NeoAxis.Component_ProjectSettings_PageBasic
	{
		Name = Shortcuts
	}
	.component NeoAxis.Component_ProjectSettings_PageBasic
	{
		Name = Custom Splash Screen
	}
}";
                        var fileName = Path.Combine(creationDirectory, @"Assets\Base\ProjectSettings.component");
                        File.WriteAllText(fileName, content);
                    }

                    //make zip archive
                    {
                        var fileName = tag == "PublicBuild" ? "Default project with Starter Content, Sci-fi Demo, Nature Demo, Test scenes.zip" : "Default project with Starter Content.zip";
                        //var fileName = tag == "PublicBuild" ? "Default project with sample content.zip" : "Empty project.zip";
                        var zipfileName = Path.Combine(creationDirectory, fileName);

                        //can't write zip file to same folder. using temp file.
                        var tempFileName = Path.GetTempPath() + Guid.NewGuid().ToString() + ".zip";
                        ZipFile.CreateFromDirectory(creationDirectory, tempFileName, CompressionLevel.Optimal, false);
                        File.Copy(tempFileName, zipfileName);
                        File.Delete(tempFileName);

                        //ZipFile.CreateFromDirectory( creationDirectory, zipfileName, CompressionLevel.Optimal, false );
                    }
                }

                creationProgressBarValue = 100;

                //open folder
                try
                {
                    Win32Utility.ShellExecuteEx(null, creationDirectory);
                    //Process.Start( "explorer.exe", creationDirectory );
                }
                catch { }

                ////run process
                //string executableFileName = Path.Combine( creationDirectory, "NeoAxis.Studio.exe" );
                //var runMapProcess = Process.Start( executableFileName, "" );

                //end
                creationInProgress = false;

                ScreenNotifications.Show(Translate("The project was created successfully."));
            }
            catch (Exception ex)
            {
                EditorMessageBox.ShowWarning(ex.Message);
            }
        }