Exemplo n.º 1
0
    public override IEnumerator Execute(UTContext context)
    {
        var isSaveCopy  = saveCopy.EvaluateIn(context);
        var theFileName = "";

        if (isSaveCopy)
        {
            theFileName = filename.EvaluateIn(context);
            if (string.IsNullOrEmpty(theFileName))
            {
                throw new UTFailBuildException("You need to specify a file name when saving a copy of a scene.", this);
            }
            theFileName = UTFileUtils.FullPathToProjectPath(theFileName);

            UTFileUtils.EnsureParentFolderExists(UTFileUtils.CombineToPath(UTFileUtils.ProjectRoot, theFileName));
        }
        if (!EditorApplication.SaveScene(theFileName, isSaveCopy))
        {
            throw new UTFailBuildException("Saving the scene failed.", this);
        }
        yield return("");
    }
Exemplo n.º 2
0
    public override IEnumerator Execute(UTContext context)
    {
        var theScene = scene.EvaluateIn(context);

        if (string.IsNullOrEmpty(theScene))
        {
            throw new UTFailBuildException("You need to specify a path where the scene should be saved to.", this);
        }
        theScene = UTFileUtils.FullPathToProjectPath(theScene);

        var theFullPath = UTFileUtils.CombineToPath(UTFileUtils.ProjectRoot, theScene);

        if (File.Exists(theFullPath))
        {
            throw new UTFailBuildException("There is already a file at '" + theScene + "'.", this);
        }

        UTFileUtils.EnsureParentFolderExists(theFullPath);
        EditorApplication.NewScene();
        EditorApplication.SaveScene(theScene, false);
        yield return("");
    }
Exemplo n.º 3
0
    public override IEnumerator Execute(UTContext context)
    {
        var theBaseDirectory = baseDirectory.EvaluateIn(context);

        if (string.IsNullOrEmpty(theBaseDirectory))
        {
            theBaseDirectory = UTFileUtils.ProjectAssets;
        }

        var theOutputFileName = outputFileName.EvaluateIn(context);

        if (string.IsNullOrEmpty(theOutputFileName))
        {
            throw new UTFailBuildException("Output file name must be set", this);
        }


        if (!theOutputFileName.EndsWith(".zip"))
        {
            Debug.LogWarning("Output filename should end with .zip.", this);
        }

        if (!appendToExistingFile.EvaluateIn(context))
        {
            if (File.Exists(theOutputFileName))
            {
                if (UTPreferences.DebugMode)
                {
                    Debug.Log("Deleting existing ZIP file: " + theOutputFileName);
                }
                File.Delete(theOutputFileName);
            }
        }

        var theIncludes = EvaluateAll(includes, context);
        var theExcludes = EvaluateAll(excludes, context);

        var fileList = UTFileUtils.CalculateFileset(theBaseDirectory, theIncludes, theExcludes, UTFileUtils.FileSelectionMode.Files);

        if (fileList.Length == 0)
        {
            throw new UTFailBuildException("There is nothing to ZIP.", this);
        }

        Debug.Log("Zipping " + fileList.Length + " files.", this);

        UTFileUtils.EnsureParentFolderExists(theOutputFileName);

        var doFlatten = flattenStructure.EvaluateIn(context);
        var theBaseFolderInZipFile = baseFolderInZIPFile.EvaluateIn(context);

        using (ZipFile zf = new ZipFile(theOutputFileName)) {
            foreach (var file in fileList)
            {
                if (UTPreferences.DebugMode)
                {
                    Debug.Log("Zipping: " + file, this);
                }
                if (doFlatten)
                {
                    zf.AddFile(file, theBaseFolderInZipFile);
                }
                else
                {
                    var relativePath = UTFileUtils.StripBasePath(UTFileUtils.GetParentPath(file), theBaseDirectory);
                    zf.AddFile(file, UTFileUtils.CombineToPath(theBaseFolderInZipFile, relativePath));
                }
                yield return("");
            }
            zf.Save();
        }

        Debug.Log("ZIP file created at " + theOutputFileName, this);
        yield return("");
    }
Exemplo n.º 4
0
 /// <summary>
 /// Combines the given path segments into a path.
 /// </summary>
 public string CombinePath(params string[] parts)
 {
     return(UTFileUtils.CombineToPath(parts));
 }