Exemple #1
0
        public Pack(PackCollection collection, DirectoryInfo dataDirectory, PackIdentifier id)
        {
            if (dataDirectory == null)
            {
                throw new ArgumentNullException("dataDirectory");
            }
            if (!dataDirectory.Exists)
            {
                throw new DirectoryNotFoundException();
            }

            Collection    = collection;
            DataDirectory = dataDirectory;
            this.Id       = id;

            var indexPath  = Path.Combine(DataDirectory.FullName, id.Expansion, string.Format(IndexFileFormat, Id.TypeKey, Id.ExpansionKey, Id.Number));
            var index2Path = Path.Combine(DataDirectory.FullName, id.Expansion, string.Format(Index2FileFormat, Id.TypeKey, Id.ExpansionKey, Id.Number));

            if (IOFile.Exists(indexPath))
            {
                Source = new IndexSource(this, new Index(id, indexPath));
            }
            else if (IOFile.Exists(index2Path))
            {
                Source = new Index2Source(this, new Index2(id, index2Path));
            }
            else
            {
                throw new FileNotFoundException();
            }
        }
Exemple #2
0
        public IActionResult Index()
        {
            if (!IOFile.Exists("synosettings.json"))
            {
                return(RedirectToAction(nameof(Settings)));
            }

            var settings = JsonConvert.DeserializeObject <SettingsViewModel>(IOFile.ReadAllText("synosettings.json"));

            return(View());
        }
Exemple #3
0
        public IActionResult Settings()
        {
            SettingsViewModel model = null;

            if (IOFile.Exists("synosettings.json"))
            {
                model = JsonConvert.DeserializeObject <SettingsViewModel>(IOFile.ReadAllText("synosettings.json"));
            }

            return(View(model));
        }
Exemple #4
0
 private static void RecreateConfigurationFileIfMissing(string configurationFile)
 {
     if (!IOFile.Exists(configurationFile))
     {
         try
         {
             Log.Warning("Configuration file {ConfigurationFile} does not exist; creating from example", configurationFile);
             var source      = Path.Combine(AppContext.BaseDirectory, "config", $"{AppName}.example.yml");
             var destination = configurationFile;
             IOFile.Copy(source, destination);
         }
         catch (Exception ex)
         {
             Log.Error("Failed to create configuration file {ConfigurationFile}: {Message}", configurationFile, ex.Message);
         }
     }
 }
Exemple #5
0
        public ActionResult SupprimerPublication(int?id, string confirmer, string annuler)
        {
            if (!String.IsNullOrEmpty(confirmer) && String.IsNullOrEmpty(annuler))
            {
                PUBLICATION pub = null;

                try
                {
                    if (id == null)
                    {
                        throw new ArgumentNullException("id");
                    }

                    pub = db.GetPublication(id).First();
                }
                catch
                {
                    TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.ERREUR, Resources.Publication.idPublicationInvalide);
                }

                if (pub != null)
                {
                    db.SupprimerPublication(id);

                    string cheminEnvoi = Fichiers.CheminEnvois(pub.NOMFICHIERSERVEUR);

                    if (IOFile.Exists(cheminEnvoi))
                    {
                        IOFile.Delete(cheminEnvoi);
                    }

                    TempData[Constantes.CLE_MSG_RETOUR] = new Message(Message.TYPE_MESSAGE.SUCCES, Resources.Publication.publicationSupprimee);
                }
            }

            return(RedirectToAction("Publications", "Sectoriel"));
        }
Exemple #6
0
        public ActionResult Html2Png(int width, int height, string html)
        {
            // fit to max 1920 x 1080.
            if (width > 1920)
            {
                var scale = 1920.0 / width;
                width  = 1920;
                height = (int)(height * scale);
            }
            if (height > 1080)
            {
                var scale = 1080.0 / height;
                width  = (int)(width * scale);
                height = 1080;
            }

            // Realize html string to file.
            var htmlFilePath = Server.MapPath("~/App_Data/" + Guid.NewGuid().ToString("N") + ".html");

            IOFile.WriteAllText(htmlFilePath, html);

            // Prepare for save image file.
            var imageFilePath = Server.MapPath("~/App_Data/" + Guid.NewGuid().ToString("N") + ".png");
            var imageBytes    = default(byte[]);

            try
            {
                // Launch PhantomJS and take a screen shot into image file.
                var procInfo = new ProcessStartInfo
                {
                    FileName  = Server.MapPath("~/bin/phantomjs.exe"),
                    Arguments = string.Format("\"{0}\" {1} {2} \"{3}\" \"{4}\"",
                                              Server.MapPath("~/bin/take-screen-shot.js"),
                                              width,
                                              height,
                                              htmlFilePath,
                                              imageFilePath)
                };
                var proc = Process.Start(procInfo);
                proc.WaitForExit();
            }
            finally
            {
                // Sweep the html file.
                if (IOFile.Exists(htmlFilePath))
                {
                    try { IOFile.Delete(htmlFilePath); }
                    catch (Exception)
                    {
                        // TODO: Report
                    }
                }

                // Read image file into memory and sweep the image file.
                if (IOFile.Exists(imageFilePath))
                {
                    try
                    {
                        imageBytes = IOFile.ReadAllBytes(imageFilePath);
                        IOFile.Delete(imageFilePath);
                    }
                    catch (Exception)
                    {
                        // TODO: Report
                    }
                }
            }

            // Respond to client.
            if (imageBytes != null)
            {
                return(new FileContentResult(imageBytes, "image/png"));
            }
            else
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
        }
Exemple #7
0
        public override bool Compile(GameAssetType gameAsset, Uri baseUri, BinaryAsset asset, XmlNode node, GameDefinition game,
                                     string trace, ref int position, out string ErrorDescription)
        {
            List <TerrainTextureTileRuntime> tiles = new List <TerrainTextureTileRuntime>();
            List <XmlNode> nodes = new List <XmlNode>();

            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.Name == "Tile")
                {
                    nodes.Add(childNode);
                }
            }

            FileHelper.SetInt(nodes.Count, 4, asset.Content);
            BinaryAsset tileList = new BinaryAsset(12 * nodes.Count);

            asset.SubAssets.Add(8, tileList);
            DDSFile[,] textureList = new DDSFile[nodes.Count, 2];
            BinaryAsset baseAsset   = new BinaryAsset(0);
            BinaryAsset normalAsset = new BinaryAsset(0);
            uint        positionX   = 16;
            uint        positionY   = 16;
            uint        nextX       = 0;

            for (int idx = 0; idx < nodes.Count; ++idx)
            {
                FileHelper.SetUInt(uint.Parse(nodes[idx].Attributes["TextureID"].Value), idx * 12, tileList.Content);
                string baseTexture = nodes[idx].Attributes["BaseTexture"].Value;
                baseTexture = baseTexture.Substring(baseTexture.LastIndexOf(Path.DirectorySeparatorChar) + 1);
                baseTexture = baseTexture.Substring(baseTexture.LastIndexOf('/') + 1);
                baseTexture = baseTexture.Substring(0, baseTexture.LastIndexOf('.'));
                string baseTexturePath = Macro.Terrain + baseTexture + ".dds";
                if (!IOFile.Exists(baseTexturePath))
                {
                    ErrorDescription = string.Format("{0} doesn't exist.", baseTexturePath);
                    return(false);
                }
                using (FileStream textureStream = new FileStream(baseTexturePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (BinaryReader textureReader = new BinaryReader(textureStream))
                    {
                        textureList[idx, 0] = new DDSFile(textureReader.ReadBytes((int)(textureStream.Length)));
                    }
                }
                string normalTexture = nodes[idx].Attributes["NormalTexture"].Value;
                normalTexture = normalTexture.Substring(normalTexture.LastIndexOf(Path.DirectorySeparatorChar) + 1);
                normalTexture = normalTexture.Substring(normalTexture.LastIndexOf('/') + 1);
                normalTexture = normalTexture.Substring(0, normalTexture.LastIndexOf('.'));
                string normalTexturePath = Macro.Terrain + normalTexture + ".dds";
                if (!IOFile.Exists(normalTexturePath))
                {
                    ErrorDescription = string.Format("{0} doesn't exist.", normalTexturePath);
                    return(false);
                }
                using (FileStream textureStream = new FileStream(normalTexturePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (BinaryReader textureReader = new BinaryReader(textureStream))
                    {
                        textureList[idx, 1] = new DDSFile(textureReader.ReadBytes((int)(textureStream.Length)));
                    }
                }
            }

            // fixed height, automatically calculated width
            ushort atlasWidth  = 0;
            ushort atlasHeight = 1152;

            /*
             * foreach (XmlAttribute attribute in node.Attributes)
             * {
             *      switch (attribute.Name)
             *      {
             *              case "AtlasSize":
             *                      atlasSize = ushort.Parse(attribute.Value);
             *                      break;
             *      }
             * }
             */
            byte[,,] baseContent   = new byte[0, atlasHeight, 4];
            byte[,,] normalContent = new byte[0, atlasHeight, 4];
            uint colWidth = 0;

            for (int tileIdx = 0; tileIdx < textureList.Length >> 1; ++tileIdx)
            {
                uint size = textureList[tileIdx, 0].Header.Height;
                colWidth = Math.Max(size + 32, colWidth);

                if (positionY + size + 16 > atlasHeight)
                {
                    positionY  = 16;
                    positionX += nextX;
                    colWidth   = size + 32;
                }

                atlasWidth    = (ushort)(positionX + colWidth - 16);
                baseContent   = ResizeArray <byte>(baseContent, atlasWidth, atlasHeight, 4);
                normalContent = ResizeArray <byte>(normalContent, atlasWidth, atlasHeight, 4);

                byte[] color  = textureList[tileIdx, 0].Content.GetColor(size, size);
                byte[] normal = textureList[tileIdx, 1].Content.GetColor(size, size);

                for (int idy = -16; idy < size + 16; ++idy)
                {
                    for (int idx = -16; idx < size + 16; ++idx)
                    {
                        int tileY = idy;
                        if (tileY < 0)
                        {
                            tileY = (int)(size + tileY);
                        }
                        else if (tileY >= size)
                        {
                            tileY = (int)(tileY - size);
                        }
                        int tileX = idx;
                        if (tileX < 0)
                        {
                            tileX = (int)(size + tileX);
                        }
                        else if (tileX >= size)
                        {
                            tileX = (int)(tileX - size);
                        }
                        baseContent[(positionX + idx), (positionY + idy), 0]   = color[tileY * size * 4 + tileX * 4];
                        baseContent[(positionX + idx), (positionY + idy), 1]   = color[tileY * size * 4 + tileX * 4 + 1];
                        baseContent[(positionX + idx), (positionY + idy), 2]   = color[tileY * size * 4 + tileX * 4 + 2];
                        baseContent[(positionX + idx), (positionY + idy), 3]   = color[tileY * size * 4 + tileX * 4 + 3];
                        normalContent[(positionX + idx), (positionY + idy), 0] = normal[tileY * size * 4 + tileX * 4];
                        normalContent[(positionX + idx), (positionY + idy), 1] = normal[tileY * size * 4 + tileX * 4 + 1];
                        normalContent[(positionX + idx), (positionY + idy), 2] = normal[tileY * size * 4 + tileX * 4 + 2];
                        normalContent[(positionX + idx), (positionY + idy), 3] = normal[tileY * size * 4 + tileX * 4 + 3];
                    }
                }

                FileHelper.SetUShort((ushort)positionX, 12 * tileIdx + 4, tileList.Content);
                FileHelper.SetUShort((ushort)positionY, 12 * tileIdx + 6, tileList.Content);
                FileHelper.SetUShort((ushort)(positionX + size), 12 * tileIdx + 8, tileList.Content);
                FileHelper.SetUShort((ushort)(positionY + size), 12 * tileIdx + 10, tileList.Content);
                positionY += size + 32;
                nextX      = Math.Max(size + 32, nextX);
            }

            byte[] baseContentArray   = new byte[atlasWidth * atlasHeight * 4];
            byte[] normalContentArray = new byte[atlasWidth * atlasHeight * 4];

            for (int h = 0; h < atlasHeight; ++h)
            {
                for (int w = 0; w < atlasWidth; ++w)
                {
                    for (int c = 0; c < 4; ++c)
                    {
                        baseContentArray[(h * atlasWidth * 4) + (w * 4) + c]   = baseContent[w, h, c];
                        normalContentArray[(h * atlasWidth * 4) + (w * 4) + c] = normalContent[w, h, c];
                    }
                }
            }

            bool hasAlpha = false;

            for (int idx = 0; idx < nodes.Count; ++idx)
            {
                if (textureList[idx, 0].HasAlpha())
                {
                    hasAlpha = true;
                    break;
                }
            }
            DDSFile baseAtlas = null;

            if (hasAlpha)
            {
                baseAtlas = new DDSFile(atlasWidth, atlasHeight, 5, DDSType.DXT5, baseContentArray);
            }
            else
            {
                baseAtlas = new DDSFile(atlasWidth, atlasHeight, 5, DDSType.DXT1, baseContentArray);
            }
            hasAlpha = false;
            for (int idx = 0; idx < nodes.Count; ++idx)
            {
                if (textureList[idx, 1].HasAlpha())
                {
                    hasAlpha = true;
                    break;
                }
            }
            DDSFile normalAtlas = null;

            if (hasAlpha)
            {
                normalAtlas = new DDSFile(atlasWidth, atlasHeight, 5, DDSType.A1R5G5B5, normalContentArray);
            }
            else
            {
                normalAtlas = new DDSFile(atlasWidth, atlasHeight, 5, DDSType.R5G6B5, normalContentArray);
            }
            baseAsset.Content = baseAtlas.Binary;
            asset.SubAssets.Add(0x0C, baseAsset);
            FileHelper.SetInt(baseAsset.Content.Length, 0x10, asset.Content);
            normalAsset.Content = normalAtlas.Binary;
            asset.SubAssets.Add(0x14, normalAsset);
            FileHelper.SetInt(normalAsset.Content.Length, 0x18, asset.Content);
            ErrorDescription = string.Empty;
            return(true);
        }
Exemple #8
0
    public async Task <int> OnExecuteAsync()
    {
        var sess = _main.GetSession();

        using var client = sess.GetClient();

        var vault = Vault == null
            ? null
            : _main.GetVault(client, Vault !);

        if (vault == null && Vault != null)
        {
            return(1);
        }

        var record = _main.GetRecord(client, ref vault, Record !);

        if (record == null || vault == null)
        {
            return(1);
        }

        if (!IOFile.Exists(File))
        {
            _console.WriteError("could not find input file.");
            return(1);
        }

        var fileContent = IOFile.ReadAllText(File);
        var fileInput   = JsonSerializer.Deserialize <SetRecordInput>(fileContent,
                                                                      MainCommand.JsonInputOpts);

        if (fileInput == null)
        {
            _console.WriteError("could not read or parse input file.");
            return(1);
        }

        client.UnlockVault(vault);
        client.UnlockRecord(vault, record);

        if (record.Summary == null)
        {
            record.Summary = new();
        }
        if (record.Content == null)
        {
            record.Content = new();
        }

        SetProp(v => record.Summary.Label = v,
                fileInput.Label, fileInput.RemoveLabel);
        SetProp(v => record.Summary.Type = v,
                fileInput.Type, fileInput.RemoveType);
        SetProp(v => record.Summary.Username = v,
                fileInput.Username, fileInput.RemoveUsername);
        SetProp(v => record.Summary.Address = v,
                fileInput.Address, fileInput.RemoveAddress);
        SetProp(v => record.Content.Password = v,
                fileInput.Password, fileInput.RemovePassword);
        SetProp(v => record.Content.Memo = v,
                fileInput.Memo, fileInput.RemoveMemo);

        if (fileInput.Fields?.Length > 0 && record.Content.Fields == null)
        {
            record.Content.Fields = new();
        }

        if (record.Content.Fields != null)
        {
            if (fileInput.RemoveFields?.Length > 0)
            {
                var toDel = record.Content.Fields.Where(x =>
                                                        fileInput.RemoveFields.Contains(x.Name) &&
                                                        (fileInput.Fields == null ||
                                                         !fileInput.Fields.Any(y => object.Equals(y.Name, x.Name))));
                foreach (var f in toDel)
                {
                    record.Content.Fields.Remove(f);
                }
            }
            if (fileInput.Fields?.Length > 0)
            {
                foreach (var f in fileInput.Fields)
                {
                    var rcf = record.Content.Fields.FirstOrDefault(x => object.Equals(x.Name, f.Name));
                    if (rcf == null)
                    {
                        rcf = new();
                        record.Content.Fields.Add(rcf);
                    }
                    rcf.Name  = f.Name;
                    rcf.Type  = f.Type;
                    rcf.Value = f.Value;
                }
            }
        }

        var id = await client.SaveRecordAsync(vault, record);

        sess.Save(client);

        _console.WriteLine(id);

        return(0);
    }
Exemple #9
0
    public int OnExecute()
    {
        if (!IOFile.Exists(File))
        {
            _console.WriteError("input file not found");
            return(-1);
        }

        var inputBody = IOFile.ReadAllText(File);
        var input     = JsonSerializer.Deserialize <PasswordGeneratorInput>(inputBody,
                                                                            MainCommand.JsonInputOpts);

        // Validate the inputs
        if (input?.Classes?.Count == 0)
        {
            _console.WriteError("no Character Classes defined");
            return(1);
        }
        if (input !.Length <= 1)
        {
            _console.WriteError("missing or invalid length");
            return(1);
        }

        var totalMin = 0;
        var totalMax = 0;

        foreach (var cc in input.Classes !)
        {
            var ccChars = cc.Value.Chars;
            if (string.IsNullOrEmpty(ccChars))
            {
                _console.WriteError($"missing characters for Character Class [{cc.Key}]");
                return(1);
            }

            if (cc.Value.Min is int ccMin)
            {
                if (cc.Value.Max is int ccMinMax && ccMin > ccMinMax)
                {
                    _console.WriteError($"invalid min/max specified for Character Class [{cc.Key}]");
                    return(1);
                }

                totalMin += ccMin;
            }
            if (cc.Value.Max is int ccMax)
            {
                totalMax += ccMax;
            }
            else
            {
                totalMax = short.MaxValue;
            }
        }

        if (totalMin > input.Length)
        {
            _console.WriteError("specified minimums for Character Classes exceed total length");
            return(1);
        }
        if (totalMax < input.Length)
        {
            _console.WriteError("specified maximums for Character Classes are insufficient for total length");
            return(1);
        }

        foreach (var cc in input.Classes)
        {
            var ccChars = cc.Value.Chars !;
            while (CharsRange.Match(ccChars) is { Success: true, Groups: var g })
Exemple #10
0
    public async Task <int> OnExecuteAsync()
    {
        var sess = _main.GetSession();

        using var client = sess.GetClient();

        var vault = _main.GetVault(client, Vault !);

        if (vault == null)
        {
            return(1);
        }

        if (!IOFile.Exists(File))
        {
            _console.WriteError("could not find input file.");
            return(1);
        }

        var fileContent = IOFile.ReadAllText(File);
        var fileInput   = JsonSerializer.Deserialize <NewRecordInput>(fileContent,
                                                                      MainCommand.JsonInputOpts);

        if (fileInput == null)
        {
            _console.WriteError("could not read or parse input file.");
            return(1);
        }

        var record = new Record();

        record.Summary          = new();
        record.Summary.Label    = fileInput.Label;
        record.Summary.Type     = fileInput.Type;
        record.Summary.Username = fileInput.Username;
        record.Summary.Address  = fileInput.Address;
        record.Summary.Tags     = fileInput.Tags;

        record.Content          = new();
        record.Content.Password = fileInput.Password;
        record.Content.Memo     = fileInput.Memo;

        record.Content.Fields = fileInput.Fields?.Select(x => new RecordField
        {
            Name  = x.Name,
            Type  = x.Type,
            Value = x.Value,
        }).ToList();

        var id = await client.SaveRecordAsync(vault, record);

        sess.Save(client);

        _console.WriteLine(id);

        if (Delete)
        {
            IOFile.Delete(File);
        }

        return(0);
    }
Exemple #11
0
        public override bool Compile(GameAssetType gameAsset, Uri baseUri, BinaryAsset asset, XmlNode node, GameDefinition game,
                                     string trace, ref int position, out string ErrorDescription)
        {
            List <TerrainTextureTileRuntime> tiles = new List <TerrainTextureTileRuntime>();
            int atlasSize = 2048;

            /*foreach (XmlAttribute attribute in node.Attributes)
             * {
             *      switch (attribute.Name)
             *      {
             *              case "AtlasSize":
             *                      atlasSize = ushort.Parse(attribute.Value);
             *                      break;
             *      }
             * }*/
            List <XmlNode> nodes = new List <XmlNode>();

            foreach (XmlNode childNode in node.ChildNodes)
            {
                if (childNode.Name == "Tile")
                {
                    nodes.Add(childNode);
                }
            }
            FileHelper.SetInt(nodes.Count, 4, asset.Content);
            BinaryAsset tileList = new BinaryAsset(12 * nodes.Count);

            asset.SubAssets.Add(8, tileList);
            DDSFile[,] textureList = new DDSFile[nodes.Count, 2];
            BinaryAsset baseAsset   = new BinaryAsset(0);
            BinaryAsset normalAsset = new BinaryAsset(0);
            uint        positionX   = 16;
            uint        positionY   = 16;
            uint        nextY       = 0;

            for (int idx = 0; idx < nodes.Count; ++idx)
            {
                FileHelper.SetUInt(uint.Parse(nodes[idx].Attributes["TextureID"].Value), idx * 12, tileList.Content);
                string baseTexture = nodes[idx].Attributes["BaseTexture"].Value;
                baseTexture = baseTexture.Substring(baseTexture.LastIndexOf(Path.DirectorySeparatorChar) + 1);
                baseTexture = baseTexture.Substring(baseTexture.LastIndexOf('/') + 1);
                baseTexture = baseTexture.Substring(0, baseTexture.LastIndexOf('.'));
                string baseTexturePath = Macro.Terrain + baseTexture + ".dds";
                if (!IOFile.Exists(baseTexturePath))
                {
                    ErrorDescription = string.Format("{0} doesn't exist.", baseTexturePath);
                    return(false);
                }
                using (FileStream textureStream = new FileStream(baseTexturePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (BinaryReader textureReader = new BinaryReader(textureStream))
                    {
                        textureList[idx, 0] = new DDSFile(textureReader.ReadBytes((int)(textureStream.Length)));
                    }
                }
                string normalTexture = nodes[idx].Attributes["NormalTexture"].Value;
                normalTexture = normalTexture.Substring(normalTexture.LastIndexOf(Path.DirectorySeparatorChar) + 1);
                normalTexture = normalTexture.Substring(normalTexture.LastIndexOf('/') + 1);
                normalTexture = normalTexture.Substring(0, normalTexture.LastIndexOf('.'));
                string normalTexturePath = Macro.Terrain + normalTexture + ".dds";
                if (!IOFile.Exists(normalTexturePath))
                {
                    ErrorDescription = string.Format("{0} doesn't exist.", normalTexturePath);
                    return(false);
                }
                using (FileStream textureStream = new FileStream(normalTexturePath, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (BinaryReader textureReader = new BinaryReader(textureStream))
                    {
                        textureList[idx, 1] = new DDSFile(textureReader.ReadBytes((int)(textureStream.Length)));
                    }
                }
            }
            // For now assume each texture has the same size.
            atlasSize  = (int)textureList[0, 0].Header.Width + 32;
            atlasSize *= atlasSize * (textureList.Length >> 1);
            atlasSize  = (int)Math.Sqrt((double)atlasSize);
            --atlasSize;
            atlasSize |= atlasSize >> 1;
            atlasSize |= atlasSize >> 2;
            atlasSize |= atlasSize >> 4;
            atlasSize |= atlasSize >> 8;
            ++atlasSize;
            byte[] baseContent   = new byte[atlasSize * atlasSize * 4];
            byte[] normalContent = new byte[atlasSize * atlasSize * 4];
            for (int tileIdx = 0; tileIdx < textureList.Length >> 1; ++tileIdx)
            {
                uint size = textureList[tileIdx, 0].Header.Width;
                if (positionX + size + 16 > atlasSize)
                {
                    positionX  = 16;
                    positionY += nextY;
                }
                byte[] color  = textureList[tileIdx, 0].Content.GetColor(size, size);
                byte[] normal = textureList[tileIdx, 1].Content.GetColor(size, size);
                for (int idy = -16; idy < size + 16; ++idy)
                {
                    for (int idx = -16; idx < size + 16; ++idx)
                    {
                        int tileY = idy;
                        if (tileY < 0)
                        {
                            tileY = (int)(size + tileY);
                        }
                        else if (tileY >= size)
                        {
                            tileY = (int)(tileY - size);
                        }
                        int tileX = idx;
                        if (tileX < 0)
                        {
                            tileX = (int)(size + tileX);
                        }
                        else if (tileX >= size)
                        {
                            tileX = (int)(tileX - size);
                        }
                        baseContent[(positionY + idy) * atlasSize * 4 + (positionX + idx) * 4]       = color[tileY * size * 4 + tileX * 4];
                        baseContent[(positionY + idy) * atlasSize * 4 + (positionX + idx) * 4 + 1]   = color[tileY * size * 4 + tileX * 4 + 1];
                        baseContent[(positionY + idy) * atlasSize * 4 + (positionX + idx) * 4 + 2]   = color[tileY * size * 4 + tileX * 4 + 2];
                        baseContent[(positionY + idy) * atlasSize * 4 + (positionX + idx) * 4 + 3]   = color[tileY * size * 4 + tileX * 4 + 3];
                        normalContent[(positionY + idy) * atlasSize * 4 + (positionX + idx) * 4]     = normal[tileY * size * 4 + tileX * 4];
                        normalContent[(positionY + idy) * atlasSize * 4 + (positionX + idx) * 4 + 1] = normal[tileY * size * 4 + tileX * 4 + 1];
                        normalContent[(positionY + idy) * atlasSize * 4 + (positionX + idx) * 4 + 2] = normal[tileY * size * 4 + tileX * 4 + 2];
                        normalContent[(positionY + idy) * atlasSize * 4 + (positionX + idx) * 4 + 3] = normal[tileY * size * 4 + tileX * 4 + 3];
                    }
                }
                FileHelper.SetUShort((ushort)positionX, 12 * tileIdx + 4, tileList.Content);
                FileHelper.SetUShort((ushort)positionY, 12 * tileIdx + 6, tileList.Content);
                FileHelper.SetUShort((ushort)(positionX + size), 12 * tileIdx + 8, tileList.Content);
                FileHelper.SetUShort((ushort)(positionY + size), 12 * tileIdx + 10, tileList.Content);
                positionX += size + 32;
                nextY      = Math.Max(size + 32, nextY);
            }
            bool hasAlpha = false;

            for (int idx = 0; idx < nodes.Count; ++idx)
            {
                if (textureList[idx, 0].HasAlpha())
                {
                    hasAlpha = true;
                    break;
                }
            }
            DDSFile baseAtlas = null;

            if (hasAlpha)
            {
                baseAtlas = new DDSFile((uint)atlasSize, (uint)atlasSize, 5, DDSType.DXT5, baseContent);
            }
            else
            {
                baseAtlas = new DDSFile((uint)atlasSize, (uint)atlasSize, 5, DDSType.DXT1, baseContent);
            }
            hasAlpha = false;
            for (int idx = 0; idx < nodes.Count; ++idx)
            {
                if (textureList[idx, 1].HasAlpha())
                {
                    hasAlpha = true;
                    break;
                }
            }
            DDSFile normalAtlas = null;

            if (hasAlpha)
            {
                normalAtlas = new DDSFile((uint)atlasSize, (uint)atlasSize, 5, DDSType.A1R5G5B5, normalContent, true);
            }
            else
            {
                normalAtlas = new DDSFile((uint)atlasSize, (uint)atlasSize, 5, DDSType.R5G5B5, normalContent, true);
            }
            baseAsset.Content = baseAtlas.Binary;
            asset.SubAssets.Add(0x0C, baseAsset);
            FileHelper.SetInt(baseAsset.Content.Length, 0x10, asset.Content);
            normalAsset.Content = normalAtlas.Binary;
            asset.SubAssets.Add(0x14, normalAsset);
            FileHelper.SetInt(normalAsset.Content.Length, 0x18, asset.Content);
            ErrorDescription = string.Empty;
            return(true);
        }