Ejemplo n.º 1
0
        //[Browsable( false )]
        //public string SourcePlatformFolder
        //{
        //	get { return Path.Combine( VirtualFileSystem.Directories.Binaries, "NeoAxis.Internal\\Platforms", Platform.ToString() ); }
        //}

        public void CopyFiles(string sourceFolder, string destFolder, ProductBuildInstance buildInstance, Range progressRange, string searchPattern)
        {
            Directory.CreateDirectory(destFolder);

            var allFiles = new DirectoryInfo(sourceFolder).GetFiles(searchPattern, SearchOption.TopDirectoryOnly);

            long totalLength = allFiles.Sum(f => f.Length);

            long processedLength = 0;

            foreach (var fileInfo in allFiles)
            {
                if (File.Exists(fileInfo.FullName))
                {
                    File.Copy(fileInfo.FullName, fileInfo.FullName.Replace(sourceFolder, destFolder), true);
                }

                if (buildInstance.RequestCancel)
                {
                    buildInstance.State = ProductBuildInstance.StateEnum.Cancelled;
                    return;
                }

                processedLength += fileInfo.Length;
                buildInstance.SetProgressWithRange((double)processedLength / (double)totalLength, progressRange);
            }
        }
Ejemplo n.º 2
0
 public bool CheckCancel(ProductBuildInstance buildInstance)
 {
     if (buildInstance.RequestCancel)
     {
         buildInstance.State = ProductBuildInstance.StateEnum.Cancelled;
     }
     return(buildInstance.RequestCancel);
 }
Ejemplo n.º 3
0
        public void CopyFolder(string sourceFolder, string destFolder, ProductBuildInstance buildInstance, Range progressRange, IEnumerable <string> excludePaths = null)
        {
            if (!Directory.Exists(sourceFolder))
            {
                return;
            }

            Directory.CreateDirectory(destFolder);

            IEnumerable <FileInfo> allFiles = new DirectoryInfo(sourceFolder).GetFiles("*.*", SearchOption.AllDirectories).ToList();
            IEnumerable <string>   allDirs  = Directory.GetDirectories(sourceFolder, "*", SearchOption.AllDirectories).ToList();

            // filter if needed.
            if (excludePaths != null)
            {
                allFiles = allFiles.Where(file => excludePaths.All(p => !file.FullName.Contains(p)));
                allDirs  = allDirs.Where(dir => excludePaths.All(p => !dir.Contains(p)));
            }

            long totalLength = 0;

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

            foreach (string dirPath in allDirs)
            {
                if (Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath.Replace(sourceFolder, destFolder));
                }
            }

            long processedLength = 0;

            foreach (var fileInfo in allFiles)
            {
                if (File.Exists(fileInfo.FullName))
                {
                    File.Copy(fileInfo.FullName, fileInfo.FullName.Replace(sourceFolder, destFolder), true);
                }

                if (buildInstance.RequestCancel)
                {
                    buildInstance.State = ProductBuildInstance.StateEnum.Cancelled;
                    return;
                }

                processedLength += fileInfo.Length;
                buildInstance.SetProgressWithRange((double)processedLength / (double)totalLength, progressRange);
            }
        }
Ejemplo n.º 4
0
        public override void BuildFunction(ProductBuildInstance buildInstance)
        {
            try
            {
                PatchCSharpProjects(buildInstance);

                CopyFilesToPackageFolder(buildInstance);
                buildInstance.Progress = 0.8f;

                if (CheckCancel(buildInstance))
                {
                    return;
                }

                //if( PatchProjectFiles )
                //	DoPatchProjectFiles( buildInstance );
                //buildInstance.Progress = 0.9f;

                //if( CheckCancel( buildInstance ) )
                //	return;
            }
            catch (Exception e)
            {
                buildInstance.Error = e.Message;
                buildInstance.State = ProductBuildInstance.StateEnum.Error;
                return;
            }

            //done
            buildInstance.Progress = 1;
            buildInstance.State    = ProductBuildInstance.StateEnum.Success;

            if (CheckCancel(buildInstance))
            {
                return;
            }

            ShowSuccessScreenNotification();
        }
Ejemplo n.º 5
0
        void DoPatchProjectFiles(ProductBuildInstance buildInstance)
        {
            string destSourcesPath = Path.Combine(buildInstance.DestinationFolder, "Sources");

            PatchManifestFile(Path.Combine(destSourcesPath, "NeoAxis.Player.UWP\\Package.appxmanifest"));
            PatchCSProjFile(Path.Combine(destSourcesPath, "NeoAxis.Player.UWP\\NeoAxis.Player.UWP.csproj"));
            PatchAssemblyInfoFile(Path.Combine(destSourcesPath, "NeoAxis.Player.UWP\\Properties\\AssemblyInfo.cs"));


            //CopyFolder( GetTemplateFolder(), buildInstance.DestinationFolder, buildInstance, new Range( 0, 0.2 ) );

            //File.Move(
            //	Path.Combine( buildInstance.DestinationFolder, "ProductName.sln" ),
            //	Path.Combine( buildInstance.DestinationFolder, ProductName + ".sln" ) );

            //Directory.Move( Path.Combine( buildInstance.DestinationFolder, "ProductName" ), buildInstance.ProductFolder );

            //File.Move(
            //	Path.Combine( buildInstance.ProductFolder, "ProductName.csproj" ),
            //	Path.Combine( buildInstance.ProductFolder, ProductName + ".csproj" ) );

            //PatchSolutionFile( Path.Combine( buildInstance.DestinationFolder, ProductName + ".sln" ) );
        }
Ejemplo n.º 6
0
        void PatchCSharpProjects(ProductBuildInstance buildInstance)
        {
            var exeFileName = Path.Combine(VirtualFileSystem.Directories.EngineInternal, @"Tools\PlatformTools\ProjectDiffPatcher\bin\Debug\ProjectDiffPatcher.exe");

            {
                var param1  = Path.Combine(VirtualFileSystem.Directories.Project, @"Sources\NeoAxis.CoreExtension\NeoAxis.CoreExtension.Android.csproj");
                var param2  = Path.Combine(VirtualFileSystem.Directories.Project, @"Sources\NeoAxis.CoreExtension\NeoAxis.CoreExtension.csproj");
                var process = Process.Start(new ProcessStartInfo(exeFileName, $"\"{param1}\" \"{param2}\" Android")
                {
                    UseShellExecute = true
                });
                process.WaitForExit();
            }

            {
                var param1  = Path.Combine(VirtualFileSystem.Directories.Project, @"Project.Android.csproj");
                var param2  = Path.Combine(VirtualFileSystem.Directories.Project, @"Project.csproj");
                var process = Process.Start(new ProcessStartInfo(exeFileName, $"\"{param1}\" \"{param2}\" Android")
                {
                    UseShellExecute = true
                });
                process.WaitForExit();
            }
        }
Ejemplo n.º 7
0
        public override void BuildFunction(ProductBuildInstance buildInstance)
        {
            List <string> folders = new List <string>();

            folders.Add("Assets");
            folders.Add("Binaries");
            folders.Add("Caches");

            //copy files
            try
            {
                var percentStep    = 0.99 / folders.Count;
                var currentPercent = 0.0;

                for (int nFolder = 0; nFolder < folders.Count; nFolder++)
                {
                    var folder       = folders[nFolder];
                    var sourceFolder = Path.Combine(VirtualFileSystem.Directories.Project, folder);
                    var destFolder   = Path.Combine(buildInstance.DestinationFolder, folder);

                    //!!!!проценты от размера папки
                    var percentRange = new Range(currentPercent, currentPercent + percentStep);

                    bool skipDefaultBehavior = false;

                    var assetsExcludePaths = new List <string>();
                    assetsExcludePaths.Add(Path.Combine(sourceFolder, @"Base\Tools"));

                    if (folder == "Assets")
                    {
                        var values = SelectedAssets.Value.Trim();
                        if (!string.IsNullOrEmpty(values))
                        {
                            foreach (var v in values.Split(new char[] { ';' }))
                            {
                                var v2 = v.Trim();
                                if (!string.IsNullOrEmpty(v2))
                                {
                                    var sourceFolder2 = Path.Combine(VirtualFileSystem.Directories.Project, folder, v2);
                                    var destFolder2   = Path.Combine(buildInstance.DestinationFolder, folder, v2);
                                    var percentRange2 = new Range(percentRange.Minimum, percentRange.Minimum);

                                    CopyFolder(sourceFolder2, destFolder2, buildInstance, percentRange2, assetsExcludePaths);

                                    if (CheckCancel(buildInstance))
                                    {
                                        return;
                                    }
                                }
                            }

                            skipDefaultBehavior = true;
                        }
                    }

                    if (!skipDefaultBehavior)
                    {
                        var excludePaths = new List <string>();
                        if (folder == "Binaries")
                        {
                            excludePaths.AddRange(GetPlatformsExcludePaths());

                            excludePaths.Add(Path.Combine(sourceFolder, @"NeoAxis.Internal\Tips"));
                            excludePaths.Add(Path.Combine(sourceFolder, @"NeoAxis.Internal\Localization"));
                            excludePaths.Add(Path.Combine(sourceFolder, @"NeoAxis.Internal\Tools\PlatformTools"));

                            excludePaths.Add(Path.Combine(sourceFolder, "NeoAxis.Editor.exe"));
                            excludePaths.Add(Path.Combine(sourceFolder, "NeoAxis.Editor.exe.config"));
                            excludePaths.Add(Path.Combine(sourceFolder, "SampleWidgetWinForms.exe"));
                            excludePaths.Add(Path.Combine(sourceFolder, "SampleWidgetWinForms.exe.config"));
                            excludePaths.Add(Path.Combine(sourceFolder, "SampleWidgetWPF.exe"));
                            excludePaths.Add(Path.Combine(sourceFolder, "SampleWidgetWPF.exe.config"));

                            excludePaths.Add(Path.Combine(sourceFolder, @"NeoAxis.Internal\Platforms\Windows\dotnet"));
                            //if( !BuildTools )
                            //{
                            //	excludePaths.Add( Path.Combine( sourceFolder, @"NeoAxis.Internal\Tools\BuildTools" ) );
                            //	excludePaths.Add( Path.Combine( sourceFolder, @"NeoAxis.Internal\Tools\Framework" ) );
                            //}

                            if (!UIWebBrowser)
                            {
                                excludePaths.Add(Path.Combine(sourceFolder, @"NeoAxis.Internal\Platforms\Windows\CefGlue"));
                            }

                            if (!DebugFiles)
                            {
                                foreach (var fileName in Directory.GetFiles(sourceFolder, "*.pdb", SearchOption.TopDirectoryOnly))
                                {
                                    excludePaths.Add(fileName);
                                }
                                foreach (var fileName in Directory.GetFiles(sourceFolder, "*.xml", SearchOption.TopDirectoryOnly))
                                {
                                    excludePaths.Add(fileName);
                                }
                                foreach (var fileName in Directory.GetFiles(sourceFolder, "*.mdb", SearchOption.TopDirectoryOnly))
                                {
                                    excludePaths.Add(fileName);
                                }
                            }
                        }
                        if (folder == "Caches")
                        {
                            if (!ShaderCache)
                            {
                                excludePaths.Add(@"Caches\ShaderCache");
                            }
                            if (!FileCache)
                            {
                                excludePaths.Add(@"Caches\Files");
                            }
                        }
                        if (folder == "Assets")
                        {
                            excludePaths.AddRange(assetsExcludePaths);
                        }

                        CopyFolder(sourceFolder, destFolder, buildInstance, percentRange, excludePaths);

                        if (CheckCancel(buildInstance))
                        {
                            return;
                        }
                    }

                    currentPercent += percentStep;
                }
            }
            catch (Exception e)
            {
                buildInstance.Error = e.Message;
                buildInstance.State = ProductBuildInstance.StateEnum.Error;
                return;
            }

            ////write License.cert
            //if( EngineApp.IsProPlan )
            //{
            //	var realFileName = Path.Combine( buildInstance.DestinationFolder, "License.cert" );

            //	var date = DateTime.UtcNow;
            //	//add 10 years
            //	date = date.Add( new TimeSpan( 365 * 10, 0, 0, 0, 0 ) );

            //	if( LoginUtility.GetCurrentLicense( out var email, out _ ) )
            //	{
            //		if( !LoginUtility.SaveLicenseCertificate( realFileName, email, EngineInfo.Version, EngineApp.License, "", date, out string error ) )
            //		{
            //			//!!!!
            //		}
            //	}
            //}

            //done
            buildInstance.Progress = 1;
            buildInstance.State    = ProductBuildInstance.StateEnum.Success;

            //run
            if (buildInstance.Run)
            {
                string executableFileName = Path.Combine(buildInstance.DestinationFolder, "Binaries", ExecutableName + ".exe");
                Process.Start(executableFileName, "");
            }


            //string destBinariesDirectory = Path.Combine( buildInstance.DestinationFolder, "Files" );

            ////copy files
            //try
            //{
            //	var excludePaths = GetPlatformsExcludePaths();
            //	CopyFolder( VirtualFileSystem.Directories.Binaries, destBinariesDirectory, buildInstance, new Range( 0, 0.99 ), excludePaths );
            //}
            //catch( Exception e )
            //{
            //	buildInstance.Error = e.Message;
            //	buildInstance.State = ProductBuildInstance.StateEnum.Error;
            //	return;
            //}

            ////done
            //buildInstance.Progress = 1;
            //buildInstance.State = ProductBuildInstance.StateEnum.Success;

            ////run
            //if( buildInstance.Run )
            //{
            //	string executableFileName = Path.Combine( destBinariesDirectory, ExecutableName + ".exe" );
            //	var runMapProcess = Process.Start( executableFileName, "" );
            //}

            if (CheckCancel(buildInstance))
            {
                return;
            }

            ShowSuccessScreenNotification();
        }
Ejemplo n.º 8
0
        //string GetComponentFolder()
        //{
        //	var realPath = VirtualPathUtility.GetRealPathByVirtual( HierarchyController.CreatedByResource.Owner.Name );
        //	return Path.GetDirectoryName( realPath );
        //	//var path = HierarchyController.CreatedByResource.Owner.Name;
        //	//var fullPath = Path.Combine( VirtualFileSystem.Directories.ProjectData, path );
        //	//return Path.GetDirectoryName( fullPath );
        //}

        //string GetTemplateFolder()
        //{
        //	return Path.Combine( GetComponentFolder(), "ProjectTemplate" );
        //}

        void CopyFilesToPackageFolder(ProductBuildInstance buildInstance)
        {
            //copy Assets
            {
                string sourceAssetsPath = VirtualFileSystem.Directories.Assets;
                string destAssetsPath   = Path.Combine(buildInstance.DestinationFolder, "Assets");

                var assetsExcludePaths = new List <string>();
                assetsExcludePaths.Add(Path.Combine(sourceAssetsPath, @"Base\Tools"));

                bool skipDefaultBehavior = false;

                var values = SelectedAssets.Value.Trim();
                if (!string.IsNullOrEmpty(values))
                {
                    foreach (var v in values.Split(new char[] { ';' }))
                    {
                        var v2 = v.Trim();
                        if (!string.IsNullOrEmpty(v2))
                        {
                            var sourceFolder2 = Path.Combine(VirtualFileSystem.Directories.Project, "Assets", v2);
                            var destFolder2   = Path.Combine(buildInstance.DestinationFolder, "Assets", v2);
                            var percentRange2 = new Range(0.0, 0.0);

                            CopyFolder(sourceFolder2, destFolder2, buildInstance, percentRange2, assetsExcludePaths);

                            if (CheckCancel(buildInstance))
                            {
                                return;
                            }
                        }
                    }

                    skipDefaultBehavior = true;
                }

                if (!skipDefaultBehavior)
                {
                    CopyFolder(VirtualFileSystem.Directories.Assets, destAssetsPath, buildInstance, new Range(0.0, 0.3), assetsExcludePaths);
                }
            }

            //copy Caches
            {
                string sourceCachesPath = Path.Combine(VirtualFileSystem.Directories.Project, "Caches");
                string destCachesPath   = Path.Combine(buildInstance.DestinationFolder, "Caches");

                var excludePaths = new List <string>();
                if (!ShaderCache)
                {
                    excludePaths.Add(@"Caches\ShaderCache");
                }
                if (!FileCache)
                {
                    excludePaths.Add(@"Caches\Files");
                }

                CopyFolder(sourceCachesPath, destCachesPath, buildInstance, new Range(0.3, 0.4), excludePaths);

                if (CheckCancel(buildInstance))
                {
                    return;
                }
            }

            //copy part of Sources
            var    sourceSourcesPath = Path.Combine(VirtualFileSystem.Directories.Project, "Sources");
            string destSourcesPath   = Path.Combine(buildInstance.DestinationFolder, "Sources");

            //copy Sources\Sources.UWP.sln
            CopyFiles(sourceSourcesPath, destSourcesPath, buildInstance, new Range(0.4, 0.4), "Sources.UWP.sln");
            //copy Sources\NeoAxis.Player.UWP
            CopyFolder(Path.Combine(sourceSourcesPath, "NeoAxis.Player.UWP"), Path.Combine(destSourcesPath, "NeoAxis.Player.UWP"), buildInstance, new Range(0.4, 0.5));

            var    sourceBinariesPath = VirtualFileSystem.Directories.Binaries;
            string destBinariesPath   = Path.Combine(buildInstance.DestinationFolder, "Binaries");

            var sourcePlatformFolder = Path.Combine(sourceBinariesPath, "NeoAxis.Internal\\Platforms", Platform.ToString());
            var destPlatformFolder   = Path.Combine(destBinariesPath, "NeoAxis.Internal\\Platforms", Platform.ToString());

            //copy managed dll references from original folder
            CopyFiles(VirtualFileSystem.Directories.Binaries, destBinariesPath, buildInstance, new Range(0.5, 0.6), "*.dll");
            //copy NeoAxis.DefaultSettings.config
            File.Copy(
                Path.Combine(VirtualFileSystem.Directories.Binaries, "NeoAxis.DefaultSettings.config"),
                Path.Combine(destBinariesPath, "NeoAxis.DefaultSettings.config"));

            //!!!!unnecessary dlls are copied? we need a list of references?
            //copy managed dll references from UWP folder
            CopyFiles(
                Path.Combine(sourcePlatformFolder, "Managed"),
                Path.Combine(destPlatformFolder, "Managed"), buildInstance, new Range(0.6, 0.7), "*.dll");

            if (CheckCancel(buildInstance))
            {
                return;
            }

            //copy native dlls
            CopyFolder(
                Path.Combine(sourcePlatformFolder, BuildPlatform),
                Path.Combine(destPlatformFolder, BuildPlatform), buildInstance, new Range(0.7, 0.8));


            ////copy assets
            //if( !string.IsNullOrEmpty( AssetsFolderOverride ) )
            //{
            //	CopyFolder( Path.Combine( GetComponentFolder(), AssetsFolderOverride ), Path.Combine( buildInstance.ProductFolder, "Assets" ), buildInstance, new Range( 0.6, 0.7 ) );
            //}

            //TODO: need to more carefully prepare a Data folder for deploy.
            //if( Directory.Exists( Path.Combine( destAssetsPath, "obj" ) ) )
            //	Directory.Delete( Path.Combine( destAssetsPath, "obj" ), true );
            //if( Directory.Exists( Path.Combine( destAssetsPath, "Base\\Build" ) ) )
            //	Directory.Delete( Path.Combine( destAssetsPath, "Base\\Build" ), true );
        }
Ejemplo n.º 9
0
        public override void BuildFunction(ProductBuildInstance buildInstance)
        {
            // To build UWP app, Universal Windows SDK should be installed.
            // To register app Visual Studio should be installed.
            //TODO: check this before build / deploy

            try
            {
                CopyFilesToPackageFolder(buildInstance);
                buildInstance.Progress = 0.8f;

                if (CheckCancel(buildInstance))
                {
                    return;
                }

                if (PatchProjectFiles)
                {
                    DoPatchProjectFiles(buildInstance);
                }
                buildInstance.Progress = 0.9f;

                if (CheckCancel(buildInstance))
                {
                    return;
                }

                //!!!!does not work
                //if( buildInstance.Run )
                //{
                //	if( !BuildProject( buildInstance.DestinationFolder ) )
                //	{
                //		// exit if building failed.
                //		//TODO: pass error messsage to this point.
                //		buildInstance.Error = "Project building failed. See details in log.";
                //		buildInstance.State = ProductBuildInstance.StateEnum.Error;
                //		return;
                //	}

                //	buildInstance.Progress = 0.7f;

                //	if( CheckCancel( buildInstance ) ) return;

                //	RegisterLayout( buildInstance.DestinationFolder );

                //	if( CheckCancel( buildInstance ) ) return;
                //}
            }
            catch (Exception e)
            {
                buildInstance.Error = e.Message;
                buildInstance.State = ProductBuildInstance.StateEnum.Error;
                return;
            }

            //done
            buildInstance.Progress = 1;
            buildInstance.State    = ProductBuildInstance.StateEnum.Success;

            //!!!!does not work
            //try
            //{
            //	if( buildInstance.Run )
            //		Run();
            //}
            //catch( Exception e )
            //{
            //	Log.Warning( "Application run failed: " + e.Message ); // or Error ?
            //}

            if (CheckCancel(buildInstance))
            {
                return;
            }

            ShowSuccessScreenNotification();
        }
Ejemplo n.º 10
0
        //protected bool BuildCopyFiles( PackageBuildInstance buildInstance, Range progressRange )
        //{
        //	try
        //	{
        //		string sourcePath = VirtualFileSystem.Directories.Executables;

        //		string destBinariesDirectory = Path.Combine( buildInstance.DestinationFolder, "Files" );
        //		Directory.CreateDirectory( destBinariesDirectory );

        //		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, destBinariesDirectory ) );
        //		}

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

        //			if( buildInstance.RequestCancel )
        //			{
        //				buildInstance.State = PackageBuildInstance.StateEnum.Cancelled;
        //				return false;
        //			}

        //			processedLength += fileInfo.Length;

        //			var progress = (double)processedLength / (double)totalLength;
        //			if( progress > 1 )
        //				progress = 1;
        //			var progress2 = progressRange.Minimum + progress * progressRange.Size;
        //			buildInstance.Progress = (float)progress2;
        //			//deployProgressBarValue = (int)( (double)processedLength / (double)totalLength * 100.0 );
        //			//if( deployProgressBarValue > 100 )
        //			//	deployProgressBarValue = 100;
        //		}

        //		//delete not needed files

        //		//!!!! delete Platforms makes sense only for Windows (not for UWP) !
        //		//TODO: need to extract method and use polymorphysm. (virtual/override)
        //		if( Platform != SystemSettings.Platform.UWP )
        //		{
        //			{
        //				//delete from Platforms

        //				string platformName = Platform.ToString();
        //				string platformsPath = Path.Combine( destBinariesDirectory, "NeoAxis.Internal\\Platforms" );

        //				foreach( var directory in Directory.GetDirectories( platformsPath ) )
        //				{
        //					if( Path.GetFileName( directory ) != platformName )
        //						Directory.Delete( directory, true );
        //				}
        //			}
        //		}
        //	}
        //	catch( Exception e )
        //	{
        //		buildInstance.Error = e.Message;
        //		buildInstance.State = PackageBuildInstance.StateEnum.Error;
        //		return false;
        //	}

        //	return true;
        //}

        public abstract void BuildFunction(ProductBuildInstance buildInstance);
Ejemplo n.º 11
0
        void CopyFilesToPackageFolder(ProductBuildInstance buildInstance)
        {
            //copy Assets
            {
                string sourceAssetsPath = VirtualFileSystem.Directories.Assets;
                string destAssetsPath   = Path.Combine(buildInstance.DestinationFolder, "Assets");

                var assetsExcludePaths = new List <string>();
                assetsExcludePaths.Add(Path.Combine(sourceAssetsPath, @"Base\Tools"));

                bool skipDefaultBehavior = false;

                var values = SelectedAssets.Value.Trim();
                if (!string.IsNullOrEmpty(values))
                {
                    foreach (var v in values.Split(new char[] { ';' }))
                    {
                        var v2 = v.Trim();
                        if (!string.IsNullOrEmpty(v2))
                        {
                            var sourceFolder2 = Path.Combine(VirtualFileSystem.Directories.Project, "Assets", v2);
                            var destFolder2   = Path.Combine(buildInstance.DestinationFolder, "Assets", v2);
                            var percentRange2 = new Range(0.0, 0.0);

                            CopyFolder(sourceFolder2, destFolder2, buildInstance, percentRange2, assetsExcludePaths);

                            if (CheckCancel(buildInstance))
                            {
                                return;
                            }
                        }
                    }

                    skipDefaultBehavior = true;
                }

                if (!skipDefaultBehavior)
                {
                    CopyFolder(VirtualFileSystem.Directories.Assets, destAssetsPath, buildInstance, new Range(0.0, 0.3), assetsExcludePaths);
                }
            }

            //copy Caches
            {
                string sourceCachesPath = Path.Combine(VirtualFileSystem.Directories.Project, "Caches");
                string destCachesPath   = Path.Combine(buildInstance.DestinationFolder, "Caches");

                var excludePaths = new List <string>();
                if (!ShaderCache)
                {
                    excludePaths.Add(@"Caches\ShaderCache");
                }
                if (!FileCache)
                {
                    excludePaths.Add(@"Caches\Files");
                }

                CopyFolder(sourceCachesPath, destCachesPath, buildInstance, new Range(0.3, 0.4), excludePaths);

                if (CheckCancel(buildInstance))
                {
                    return;
                }
            }

            //copy Binaries
            {
                string sourceFolder = Path.Combine(VirtualFileSystem.Directories.Project, "Binaries");
                string destFolder   = Path.Combine(buildInstance.DestinationFolder, "Binaries");

                var excludePaths = new List <string>();
                excludePaths.AddRange(GetPlatformsExcludePaths());

                CopyFolder(sourceFolder, destFolder, buildInstance, new Range(0.4, 0.5), excludePaths);

                if (CheckCancel(buildInstance))
                {
                    return;
                }
            }

            //copy part of Sources
            {
                var    sourceFolder = Path.Combine(VirtualFileSystem.Directories.Project, "Sources");
                string destFolder   = Path.Combine(buildInstance.DestinationFolder, "Sources");
                //copy Sources\Sources.Android.sln
                CopyFiles(sourceFolder, destFolder, buildInstance, new Range(0.5, 0.6), "Sources.Android.sln");
                //copy Sources\NeoAxis.Player.Android
                CopyFolder(Path.Combine(sourceFolder, "NeoAxis.Player.Android"), Path.Combine(destFolder, "NeoAxis.Player.Android"), buildInstance, new Range(0.6, 0.7));
            }

            //create Project.zip
            {
                var destinationFileName = Path.Combine(buildInstance.DestinationFolder, @"Sources\NeoAxis.Player.Android\Assets\Project.zip");
                var compressionLevel    = CompressData.Value ? CompressionLevel.Optimal : CompressionLevel.NoCompression;

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

                var paths = new List <string>();
                paths.Add(Path.Combine(buildInstance.DestinationFolder, "Assets"));
                paths.Add(Path.Combine(buildInstance.DestinationFolder, @"Binaries\NeoAxis.DefaultSettings.config"));
                paths.Add(Path.Combine(buildInstance.DestinationFolder, "Caches"));

                using (var archive = ZipFile.Open(destinationFileName, ZipArchiveMode.Create))
                {
                    foreach (var path in paths)
                    {
                        if (Directory.Exists(path))
                        {
                            foreach (var file in Directory.GetFiles(path, "*.*", SearchOption.AllDirectories))
                            {
                                //read
                                var bytes = File.ReadAllBytes(file);

                                //write
                                var fileName = file.Substring(buildInstance.DestinationFolder.Length + 1);
                                var entry    = archive.CreateEntry(fileName, compressionLevel);
                                using (var stream = entry.Open())
                                    stream.Write(bytes, 0, bytes.Length);
                            }
                        }
                        else if (File.Exists(path))
                        {
                            //read
                            var bytes = File.ReadAllBytes(path);

                            //write
                            var fileName = path.Substring(buildInstance.DestinationFolder.Length + 1);
                            var entry    = archive.CreateEntry(fileName, compressionLevel);
                            using (var stream = entry.Open())
                                stream.Write(bytes, 0, bytes.Length);
                        }
                    }
                }

                //create .hash file
                {
                    string hashString = "";

                    using (var stream = File.Open(destinationFileName, FileMode.Open))
                    {
                        using (var hashAlgorithm1 = System.Security.Cryptography.SHA1.Create())
                        {
                            var hash = hashAlgorithm1.ComputeHash(stream);

                            var sb = new StringBuilder(hash.Length * 2);
                            foreach (byte b in hash)
                            {
                                sb.Append(b.ToString("X2"));
                            }

                            hashString = sb.ToString();
                        }
                    }

                    var fileName = destinationFileName + ".hash";
                    File.WriteAllText(fileName, hashString);
                }
            }

            //delete Assets, Caches, Binaries\NeoAxis.Internal\Tips, Binaries\NeoAxis.Internal\Tools
            {
                var destFolder = Path.Combine(buildInstance.DestinationFolder, "Assets");
                if (Directory.Exists(destFolder))
                {
                    Directory.Delete(destFolder, true);
                }

                destFolder = Path.Combine(buildInstance.DestinationFolder, "Caches");
                if (Directory.Exists(destFolder))
                {
                    Directory.Delete(destFolder, true);
                }

                destFolder = Path.Combine(buildInstance.DestinationFolder, @"Binaries\NeoAxis.Internal\Tips");
                if (Directory.Exists(destFolder))
                {
                    Directory.Delete(destFolder, true);
                }

                destFolder = Path.Combine(buildInstance.DestinationFolder, @"Binaries\NeoAxis.Internal\Tools");
                if (Directory.Exists(destFolder))
                {
                    Directory.Delete(destFolder, true);
                }
            }
        }
Ejemplo n.º 12
0
        void CopyFilesToPackageFolder(ProductBuildInstance buildInstance)
        {
            //copy Assets
            {
                string sourceAssetsPath = VirtualFileSystem.Directories.Assets;
                string destAssetsPath   = Path.Combine(buildInstance.DestinationFolder, "Assets");

                var assetsExcludePaths = new List <string>();
                assetsExcludePaths.Add(Path.Combine(sourceAssetsPath, @"Base\Tools"));

                bool skipDefaultBehavior = false;

                var values = SelectedAssets.Value.Trim();
                if (!string.IsNullOrEmpty(values))
                {
                    foreach (var v in values.Split(new char[] { ';' }))
                    {
                        var v2 = v.Trim();
                        if (!string.IsNullOrEmpty(v2))
                        {
                            var sourceFolder2 = Path.Combine(VirtualFileSystem.Directories.Project, "Assets", v2);
                            var destFolder2   = Path.Combine(buildInstance.DestinationFolder, "Assets", v2);
                            var percentRange2 = new Range(0.0, 0.0);

                            CopyFolder(sourceFolder2, destFolder2, buildInstance, percentRange2, assetsExcludePaths);

                            if (CheckCancel(buildInstance))
                            {
                                return;
                            }
                        }
                    }

                    skipDefaultBehavior = true;
                }

                if (!skipDefaultBehavior)
                {
                    CopyFolder(VirtualFileSystem.Directories.Assets, destAssetsPath, buildInstance, new Range(0.0, 0.3), assetsExcludePaths);
                }
            }

            //copy Caches
            {
                string sourceCachesPath = Path.Combine(VirtualFileSystem.Directories.Project, "Caches");
                string destCachesPath   = Path.Combine(buildInstance.DestinationFolder, "Caches");

                var excludePaths = new List <string>();
                if (!ShaderCache)
                {
                    excludePaths.Add(@"Caches\ShaderCache");
                }
                if (!FileCache)
                {
                    excludePaths.Add(@"Caches\Files");
                }

                CopyFolder(sourceCachesPath, destCachesPath, buildInstance, new Range(0.3, 0.4), excludePaths);

                if (CheckCancel(buildInstance))
                {
                    return;
                }
            }

            //copy Build.Android.sln
            CopyFiles(VirtualFileSystem.Directories.Project, buildInstance.DestinationFolder, buildInstance, new Range(0.4, 0.4), "Build.Android.sln");

            //copy Project.Android.csproj
            CopyFiles(VirtualFileSystem.Directories.Project, buildInstance.DestinationFolder, buildInstance, new Range(0.4, 0.4), "Project.Android.csproj");

            //copy Properties
            CopyFolder(Path.Combine(VirtualFileSystem.Directories.Project, "Properties"), Path.Combine(buildInstance.DestinationFolder, "Properties"), buildInstance, new Range(0.4, 0.4));

            //copy part of Sources
            var    sourceSourcesPath = Path.Combine(VirtualFileSystem.Directories.Project, "Sources");
            string destSourcesPath   = Path.Combine(buildInstance.DestinationFolder, "Sources");

            //copy Sources\NeoAxis.Player.Android
            CopyFolder(Path.Combine(sourceSourcesPath, "NeoAxis.Player.Android"), Path.Combine(destSourcesPath, "NeoAxis.Player.Android"), buildInstance, new Range(0.4, 0.45));
            //copy Sources\NeoAxis.CoreExtension
            CopyFolder(Path.Combine(sourceSourcesPath, "NeoAxis.CoreExtension"), Path.Combine(destSourcesPath, "NeoAxis.CoreExtension"), buildInstance, new Range(0.45, 0.5));

            var    sourceBinariesPath = VirtualFileSystem.Directories.Binaries;
            string destBinariesPath   = Path.Combine(buildInstance.DestinationFolder, "Binaries");

            var sourcePlatformFolder = Path.Combine(sourceBinariesPath, "NeoAxis.Internal\\Platforms", Platform.ToString());
            var destPlatformFolder   = Path.Combine(destBinariesPath, "NeoAxis.Internal\\Platforms", Platform.ToString());

            ////copy managed dll references from original folder
            //CopyFiles( VirtualFileSystem.Directories.Binaries, destBinariesPath, buildInstance, new Range( 0.5, 0.6 ), "*.dll" );
            //copy NeoAxis.DefaultSettings.config
            Directory.CreateDirectory(destBinariesPath);
            File.Copy(
                Path.Combine(VirtualFileSystem.Directories.Binaries, "NeoAxis.DefaultSettings.config"),
                Path.Combine(destBinariesPath, "NeoAxis.DefaultSettings.config"));

            //!!!!unnecessary dlls are copied? we need a list of references?
            //copy managed dll references from Android folder
            CopyFiles(
                Path.Combine(sourcePlatformFolder, "Managed"),
                Path.Combine(destPlatformFolder, "Managed"), buildInstance, new Range(0.6, 0.7), "*.dll");

            if (CheckCancel(buildInstance))
            {
                return;
            }

            //create Project.zip
            {
                var destinationFileName = Path.Combine(buildInstance.DestinationFolder, @"Sources\NeoAxis.Player.Android\Assets\Project.zip");
                var compressionLevel    = CompressData.Value ? CompressionLevel.Optimal : CompressionLevel.NoCompression;

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

                var paths = new List <string>();
                paths.Add(Path.Combine(buildInstance.DestinationFolder, "Assets"));
                paths.Add(Path.Combine(buildInstance.DestinationFolder, @"Binaries\NeoAxis.DefaultSettings.config"));
                //!!!!without CSharpScripts
                paths.Add(Path.Combine(buildInstance.DestinationFolder, "Caches"));

                using (var archive = ZipFile.Open(destinationFileName, ZipArchiveMode.Create))
                {
                    foreach (var path in paths)
                    {
                        if (Directory.Exists(path))
                        {
                            foreach (var file in Directory.GetFiles(path, "*.*", SearchOption.AllDirectories))
                            {
                                //read
                                var bytes = File.ReadAllBytes(file);

                                //write
                                var fileName = file.Substring(buildInstance.DestinationFolder.Length + 1);
                                var entry    = archive.CreateEntry(fileName, compressionLevel);
                                entry.LastWriteTime = new DateTimeOffset(setTimeToFilesInZip);
                                using (var stream = entry.Open())
                                    stream.Write(bytes, 0, bytes.Length);
                            }
                        }
                        else if (File.Exists(path))
                        {
                            //read
                            var bytes = File.ReadAllBytes(path);

                            //write
                            var fileName = path.Substring(buildInstance.DestinationFolder.Length + 1);
                            var entry    = archive.CreateEntry(fileName, compressionLevel);
                            entry.LastWriteTime = new DateTimeOffset(setTimeToFilesInZip);
                            using (var stream = entry.Open())
                                stream.Write(bytes, 0, bytes.Length);
                        }
                    }
                }

                //create .hash file
                {
                    string hashString = "";

                    using (var stream = File.Open(destinationFileName, FileMode.Open))
                    {
                        using (var hashAlgorithm1 = System.Security.Cryptography.SHA1.Create())
                        {
                            var hash = hashAlgorithm1.ComputeHash(stream);

                            var sb = new StringBuilder(hash.Length * 2);
                            foreach (byte b in hash)
                            {
                                sb.Append(b.ToString("X2"));
                            }

                            hashString = sb.ToString();
                        }
                    }

                    var fileName = destinationFileName + ".hash";
                    File.WriteAllText(fileName, hashString);
                }
            }

            //delete Assets, Caches, Binaries\NeoAxis.Internal\Tips, Binaries\NeoAxis.Internal\Tools
            {
                //need for cs files
                //var destFolder = Path.Combine( buildInstance.DestinationFolder, "Assets" );
                //if( Directory.Exists( destFolder ) )
                //	Directory.Delete( destFolder, true );

                //need for cs files
                //destFolder = Path.Combine( buildInstance.DestinationFolder, "Caches" );
                //if( Directory.Exists( destFolder ) )
                //	Directory.Delete( destFolder, true );

                var destFolder = Path.Combine(buildInstance.DestinationFolder, @"Binaries\NeoAxis.Internal\Tips");
                if (Directory.Exists(destFolder))
                {
                    Directory.Delete(destFolder, true);
                }

                destFolder = Path.Combine(buildInstance.DestinationFolder, @"Binaries\NeoAxis.Internal\Tools");
                if (Directory.Exists(destFolder))
                {
                    Directory.Delete(destFolder, true);
                }
            }

            //copy PrepareAssetsForDebug
            {
                var sourceFolder = Path.Combine(sourceBinariesPath, @"NeoAxis.Internal\Tools\PlatformTools\PrepareAssetsForDebug");
                var destFolder   = Path.Combine(destBinariesPath, @"NeoAxis.Internal\Tools\PlatformTools\PrepareAssetsForDebug");
                CopyFolder(sourceFolder, destFolder, buildInstance, new Range(0.8, 0.9));
            }
        }