/// <summary>
        /// Combines and compresses input files using the selected method.
        /// </summary>
        /// <param name="outputFile">File to write the resulting file to</param>
        /// <param name="mode">Compression method</param>
        /// <param name="inputFiles">Files to compress</param>
        /// <param name="verbose">Display informational messages and warnings</param>
        /// <returns>Compressed files</returns>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if an unknown PackMode is provided</exception>
        public static bool Run(string outputFile, PackMode mode, string[] inputFiles, bool verbose)
        {
            string output = Run(mode, inputFiles, verbose);

            try
            {
                FileProcessor.Logger.WriteMessage("Writing output to " + outputFile, MessageType.Normal);

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

                StreamWriter sw           = new StreamWriter(outputFile, false);
                StringReader stringReader = new StringReader(output);

                while (stringReader.Peek() > 0)
                {
                    string line = stringReader.ReadLine();
                    sw.WriteLine(line);
                }

                stringReader.Close();
                sw.Close();
            }
            catch (Exception ex)
            {
                FileProcessor.Logger.WriteMessage(ex.Message, MessageType.Error);
                return(false);
            }
            return(true);
        }
Example #2
0
        public static string GetPackTag(DirectoryInfo bundleDir, FileInfo file, PackMode fPackMode, string parttern, out string abName)
        {
            abName = null;
            switch (fPackMode)
            {
            case PackMode.Indepent:
                return(null);

            case PackMode.AllInOne:
                var str1 = "__" + bundleDir.ToString() + parttern + fPackMode;
                abName = HashUtil.Get(str1) + ".ab";
                return(bundleDir.ToString() + "/" + parttern + "(" + fPackMode + ")");

            case PackMode.PerAnyDir:
                var d    = file.Directory;
                var str2 = bundleDir.ToString() + d.FullName.Replace(bundleDir.FullName, "");
                abName = HashUtil.Get("_" + str2) + ".ab";
                return(str2 + "/" + parttern + "(" + fPackMode + ")");

            case PackMode.PerSubDir:
                var dir    = file.Directory;
                var subDir = "";
                while (dir.FullName != bundleDir.FullName)
                {
                    subDir = dir.Name + "/";
                    dir    = dir.Parent;
                }
                var str = "____" + bundleDir.ToString() + subDir + parttern + fPackMode;
                abName = HashUtil.Get(str) + ".ab";
                return(bundleDir.ToString() + "/" + subDir + parttern + "(" + fPackMode + ")");

            default:
                return(null);
            }
        }
Example #3
0
        /// <summary>
        /// When overridden in a derived class, executes the task.
        /// </summary>
        /// <returns>
        /// true if the task successfully executed; otherwise, false.
        /// </returns>
        public override bool Execute()
        {
            FileProcessor.SetLogger(this);
            if (!String.IsNullOrEmpty(WorkingDirectory))
            {
                if (Directory.Exists(WorkingDirectory))
                {
                    Directory.SetCurrentDirectory(WorkingDirectory);
                }
                else
                {
                    FileProcessor.Logger.WriteMessage(
                        String.Format(Properties.Resources.PackerWorkingDirectoryNotFound, WorkingDirectory),
                        MessageType.Error);
                    return(false);
                }
            }
            PackMode      mode       = (PackMode)Enum.Parse(typeof(PackMode), Mode);
            List <string> inputFiles = new List <string>();

            foreach (ITaskItem item in InputFiles)
            {
                inputFiles.Add(item.ItemSpec);
            }
            return(FileProcessor.Run(OutputFileName, mode, inputFiles.ToArray(), Verbose));
        }
Example #4
0
    private void DoSettingsGUI()
    {
        EditorGUIUtility.labelWidth = 80;
        packMode = (PackMode)EditorGUILayout.EnumPopup("Pack Mode", packMode);
        if (packMode == PackMode.Grid)
        {
            alignment = (Alignment)EditorGUILayout.EnumPopup("Alignment", alignment);
            switch (alignment)
            {
            case Alignment.Row:
                rows = EditorGUILayout.IntField("Rows", rows);
                break;

            case Alignment.Column:
                columns = EditorGUILayout.IntField("Columns", columns);
                break;
            }
        }
        mMaxSize   = EditorGUILayout.IntField("Max Size", mMaxSize);
        trimSingle = EditorGUILayout.Toggle("Trim", trimSingle);
        if (trimSingle)
        {
            EditorGUI.indentLevel += 1;
            paddingSingle          = EditorGUILayout.IntField("Padding", paddingSingle);
            EditorGUI.indentLevel -= 1;
        }
        saveSingleSprites = EditorGUILayout.Toggle("Save Single", saveSingleSprites);

        padding = EditorGUILayout.IntField("Atlas Padding", padding);
        pivot   = (Pivot)EditorGUILayout.EnumPopup("Pivot", pivot);

        if (pivot != Pivot.CenterOfMass)
        {
            bool enabled = GUI.enabled;
            GUI.enabled = pivot == Pivot.Custom;
            if (pivot != Pivot.Custom)
            {
                pivotPosition = pivotMap [pivot];
            }
            pivotPosition = EditorGUILayout.Vector2Field("Custom Pivot", pivotPosition);
            GUI.enabled   = enabled;
        }
    }
Example #5
0
        public void AddRootTargets(DirectoryInfo bundleDir, PackMode fPackMode, string parttern = null,
                                   SearchOption searchOption = SearchOption.AllDirectories)
        {
            if (string.IsNullOrEmpty(parttern))
            {
                parttern = "*.*";
            }

            FileInfo[] prefabs = bundleDir.GetFiles(parttern, searchOption);

            foreach (FileInfo file in prefabs)
            {
                if (file.Extension.Contains("meta"))
                {
                    continue;
                }
                AssetTarget target = AssetBundleUtils.Load(file);
                target.abDebugName = AssetBundleUtils.GetPackTag(bundleDir, file, fPackMode, parttern, out var abname);
                target.abFileName  = abname;
                target.exportType  = AssetBundleExportType.Root;
            }
        }
        static void Main(string[] args)
        {
            if (args.Length == 0 || "-h".Equals(args[0]) || "-?".Equals(args[0]))
            {
                ShowUsage();
                return;
            }

            int    startIndex = 0;
            string outputFile = "output.js";

            if ("-o".Equals(args[startIndex]))
            {
                if (args.Length > startIndex + 1)
                {
                    outputFile  = args[startIndex + 1];
                    startIndex += 2;
                }
                else
                {
                    ShowUsage();
                    return;
                }
            }

            PackMode mode = PackMode.Packer;

            if ("-m".Equals(args[startIndex]))
            {
                if (args.Length > startIndex + 1)
                {
                    string str = args[startIndex + 1];
                    if ("packer".Equals(str, StringComparison.InvariantCultureIgnoreCase))
                    {
                        mode = PackMode.Packer;
                    }
                    else if ("jsmin".Equals(str, StringComparison.InvariantCultureIgnoreCase))
                    {
                        mode = PackMode.JSMin;
                    }
                    else if ("cssmin".Equals(str, StringComparison.InvariantCultureIgnoreCase))
                    {
                        mode = PackMode.CSSMin;
                    }
                    else if ("combine".Equals(str, StringComparison.InvariantCultureIgnoreCase))
                    {
                        mode = PackMode.Combine;
                    }
                    else
                    {
                        FileProcessor.Logger.WriteMessage("Mode is not recognized: " + str, MessageType.Error);
                        ShowUsage();
                        return;
                    }
                    startIndex += 2;
                }
                else
                {
                    ShowUsage();
                    return;
                }
            }

            List <string> inputFiles = new List <string>();

            for (int i = startIndex; i < args.Length; i++)
            {
                string filename = args[i];
                // expand wildcard
                if (filename.Contains("*"))
                {
                    inputFiles.AddRange(ExpandWildcard(filename));
                }
                else if (File.Exists(filename))
                {
                    inputFiles.Add(filename);
                }
            }

            FileProcessor.Run(outputFile, mode, inputFiles.ToArray(), true);
        }
        /// <summary>
        /// Combines and compresses input files using the selected method.
        /// </summary>
        /// <param name="outputFile">File to write the resulting file to</param>
        /// <param name="mode">Compression method</param>
        /// <param name="inputFiles">Files to compress</param>
        /// <param name="verbose">Display informational messages and warnings</param>
        /// <returns>Compressed files</returns>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if an unknown PackMode is provided</exception>
        public static bool Run(string outputFile, PackMode mode, string[] inputFiles, bool verbose)
        {
            string output = Run(mode, inputFiles, verbose);

            try
            {
                FileProcessor.Logger.WriteMessage("Writing output to " + outputFile, MessageType.Normal);

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

                StreamWriter sw = new StreamWriter(outputFile, false);
                StringReader stringReader = new StringReader(output);

                while (stringReader.Peek() > 0)
                {
                    string line = stringReader.ReadLine();
                    sw.WriteLine(line);
                }

                stringReader.Close();
                sw.Close();
            }
            catch (Exception ex)
            {
                FileProcessor.Logger.WriteMessage(ex.Message, MessageType.Error);
                return false;
            }
            return true;
        }
        /// <summary>
        /// Combines and compresses input files using the selected method.
        /// </summary>
        /// <param name="mode">Compression method</param>
        /// <param name="inputFiles">Files to compress</param>
        /// <param name="verbose">Display informational messages and warnings</param>
        /// <returns>Compressed content</returns>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if an unknown PackMode is provided</exception>
        public static string Run(PackMode mode, string[] inputFiles, bool verbose)
        {
            StringBuilder output = new StringBuilder();

            try
            {
                switch (mode)
                {
                    case PackMode.Packer:
                        output.AppendLine(PackerBanner);
                        break;
                    case PackMode.JSMin:
                        output.AppendLine(JsMinBanner);
                        break;
                    case PackMode.CSSMin:
                        output.AppendLine(CSSMinBanner);
                        break;
                    case PackMode.Combine:
                        output.AppendLine(CombineBanner);
                        break;
                    default:
                        throw new ArgumentOutOfRangeException("mode", mode, "Mode provided was not recognized");
                }

                foreach (string filename in inputFiles)
                {
                    StringBuilder sb = new StringBuilder();

                    if (File.Exists(filename))
                    {
                        if (verbose)
                        {
                            FileProcessor.Logger.WriteMessage("Processing " + filename, MessageType.Normal);
                            if (filename.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase))
                            {
                                output.AppendLine("// " + filename);
                            }
                            else if (filename.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase))
                            {
                                output.AppendLine("/* " + filename + " */");
                            }
                        }

                        using (StreamReader streamReader = File.OpenText(filename))
                        {
                            sb.AppendLine(streamReader.ReadToEnd());
                        }

                        // run file prrocessor on each file (to do work on smaller pieces)
                        switch (mode)
                        {
                            case PackMode.Packer:
                                output.AppendLine(RunPacker(sb.ToString()));
                                break;
                            case PackMode.JSMin:
                                output.AppendLine(RunJsMin(sb.ToString()));
                                break;
                            case PackMode.CSSMin:
                                output.AppendLine(RunCSSMin(sb.ToString()));
                                break;
                            case PackMode.Combine:
                                output.AppendLine(RunCombine(sb.ToString()));
                                break;
                        }
                    }
                    else
                    {
                        FileProcessor.Logger.WriteMessage("File does not exist: " + filename, MessageType.Warning);
                    }
                }

            }
            catch (Exception ex)
            {
                FileProcessor.Logger.WriteMessage(ex.Message, MessageType.Error);
            }
            return output.ToString();
        }
 public static extern int PackFiles(string packedFile, string subPath, string srcPath, string addList, PackMode flags);
        ArchiveResult ITotalCommanderWcxPlugin.PackFiles(string archiveName, string subPath, string sourcePath, string[] addList, PackMode mode)
        {
            var result = ArchiveResult.Default;
            var packer = GetPacker(archiveName, packerConfiguration, MemoryPackMode.None);

            if (packer != null)
            {
                packer.PackFiles(subPath, sourcePath, addList, mode);
                result = ArchiveResult.Success;
            }
            return(result);
        }
 ArchiveResult ITotalCommanderWcxPlugin.PackFiles(string archiveName, string subPath, string sourcePath, string[] addList, PackMode mode)
 {
     var result = ArchiveResult.Default;
     var packer = GetPacker(archiveName, packerConfiguration, MemoryPackMode.None);
     if (packer != null)
     {
         packer.PackFiles(subPath, sourcePath, addList, mode);
         result = ArchiveResult.Success;
     }
     return result;
 }
        /// <summary>
        /// Combines and compresses input files using the selected method.
        /// </summary>
        /// <param name="mode">Compression method</param>
        /// <param name="inputFiles">Files to compress</param>
        /// <param name="verbose">Display informational messages and warnings</param>
        /// <returns>Compressed content</returns>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if an unknown PackMode is provided</exception>
        public static string Run(PackMode mode, string[] inputFiles, bool verbose)
        {
            StringBuilder output = new StringBuilder();

            try
            {
                switch (mode)
                {
                case PackMode.Packer:
                    output.AppendLine(PackerBanner);
                    break;

                case PackMode.JSMin:
                    output.AppendLine(JsMinBanner);
                    break;

                case PackMode.CSSMin:
                    output.AppendLine(CSSMinBanner);
                    break;

                case PackMode.Combine:
                    output.AppendLine(CombineBanner);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("mode", mode, "Mode provided was not recognized");
                }

                foreach (string filename in inputFiles)
                {
                    StringBuilder sb = new StringBuilder();

                    if (File.Exists(filename))
                    {
                        if (verbose)
                        {
                            FileProcessor.Logger.WriteMessage("Processing " + filename, MessageType.Normal);
                            if (filename.EndsWith(".js", StringComparison.InvariantCultureIgnoreCase))
                            {
                                output.AppendLine("// " + filename);
                            }
                            else if (filename.EndsWith(".css", StringComparison.InvariantCultureIgnoreCase))
                            {
                                output.AppendLine("/* " + filename + " */");
                            }
                        }

                        using (StreamReader streamReader = File.OpenText(filename))
                        {
                            sb.AppendLine(streamReader.ReadToEnd());
                        }

                        // run file prrocessor on each file (to do work on smaller pieces)
                        switch (mode)
                        {
                        case PackMode.Packer:
                            output.AppendLine(RunPacker(sb.ToString()));
                            break;

                        case PackMode.JSMin:
                            output.AppendLine(RunJsMin(sb.ToString()));
                            break;

                        case PackMode.CSSMin:
                            output.AppendLine(RunCSSMin(sb.ToString()));
                            break;

                        case PackMode.Combine:
                            output.AppendLine(RunCombine(sb.ToString()));
                            break;
                        }
                    }
                    else
                    {
                        FileProcessor.Logger.WriteMessage("File does not exist: " + filename, MessageType.Warning);
                    }
                }
            }
            catch (Exception ex)
            {
                FileProcessor.Logger.WriteMessage(ex.Message, MessageType.Error);
            }
            return(output.ToString());
        }
        private async Task CheckCurrentInstanceAsync()
        {
            try
            {
                var instanceMetadata     = InstanceMetadataReader.ReadInstanceMetadata(PackBuilder.ProfilePath);
                var useCanaryVersion     = this.chkUseCanaryVersion.Checked;
                var currentRemoteVersion = useCanaryVersion
                                                                                           ? this.packMetadata.CanaryVersion ?? this.packMetadata.CurrentVersion
                                                                                           : this.packMetadata.CurrentVersion;

                // Beeg long list of checks to see if this pack needs to be completely converted or not
                if (instanceMetadata == null ||
                    instanceMetadata.Version == "0.0.0" ||
                    !SemVersion.TryParse(instanceMetadata.Version, out var instanceSemVersion) ||
                    !SemVersion.TryParse(currentRemoteVersion, out var serverSemVersion) ||
                    instanceMetadata.CurrentLaunchVersion == null ||
                    instanceMetadata.CurrentMinecraftVersion != this.packMetadata.IntendedMinecraftVersion ||
                    instanceMetadata.CurrentForgeVersion != this.packMetadata.RequiredForgeVersion ||
                    instanceMetadata.BuiltFromServerPack != this.packMetadata.ServerPack)
                {
                    // Never converted
                    this.currentPackState = PackMode.NeedsInstallation;
                }
                else
                {
                    var outOfDate = instanceSemVersion < serverSemVersion;

                    // Check server pack MD5 if necessary
                    if (this.packMetadata.VerifyServerPackMd5)
                    {
                        using var web = new WebClient();
                        var basePackMd5Url = $"{this.packMetadata.ServerPack}.md5";
                        var basePackMd5    = await web.DownloadStringTaskAsync(basePackMd5Url);

                        outOfDate |= basePackMd5 != instanceMetadata.BuiltFromServerPackMd5;
                    }

                    if (outOfDate)
                    {
                        // Out of date
                        this.currentPackState = PackMode.NeedsUpdate;
                    }
                    else
                    {
                        // Up-to-date
                        this.currentPackState = PackMode.ReadyToPlay;

                        UpdateVrUi();
                    }
                }

                this.instanceMetadata = instanceMetadata;
                UpdateLayoutFromState();
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    this,
                    $"An error occurred while checking if the instance was up-to-date:\n\n{ex}",
                    "Unexpected Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );
            }
        }