FireFileSaveEvent() 공개 정적인 메소드

public static FireFileSaveEvent ( ) : void
리턴 void
예제 #1
0
파일: Art.cs 프로젝트: uotools/Pandora
        /// <summary>
        ///     Saves mul
        /// </summary>
        /// <param name="path"></param>
        public static unsafe void Save(string path)
        {
            checksumsLand   = new List <CheckSums>();
            checksumsStatic = new List <CheckSums>();
            var idx = Path.Combine(path, "artidx.mul");
            var mul = Path.Combine(path, "art.mul");

            using (FileStream fsidx = new FileStream(idx, FileMode.Create, FileAccess.Write, FileShare.Write),
                   fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                var memidx = new MemoryStream();
                var memmul = new MemoryStream();
                var sha    = new SHA256Managed();
                //StreamWriter Tex = new StreamWriter(new FileStream("d:/artlog.txt", FileMode.Create, FileAccess.ReadWrite));

                using (BinaryWriter binidx = new BinaryWriter(memidx), binmul = new BinaryWriter(memmul))
                {
                    for (var index = 0; index < GetIdxLength(); index++)
                    {
                        Files.FireFileSaveEvent();
                        if (m_Cache[index] == null)
                        {
                            if (index < 0x4000)
                            {
                                m_Cache[index] = GetLand(index);
                            }
                            else
                            {
                                m_Cache[index] = GetStatic(index - 0x4000, false);
                            }
                        }
                        var bmp = m_Cache[index];
                        if ((bmp == null) || (m_Removed[index]))
                        {
                            binidx.Write(-1);                            // lookup
                            binidx.Write(0);                             // length
                            binidx.Write(-1);                            // extra
                            //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, (int)-1, (int)-1));
                        }
                        else if (index < 0x4000)
                        {
                            var ms = new MemoryStream();
                            bmp.Save(ms, ImageFormat.Bmp);
                            var       checksum = sha.ComputeHash(ms.ToArray());
                            CheckSums sum;
                            if (compareSaveImagesLand(checksum, out sum))
                            {
                                binidx.Write(sum.pos);                                 //lookup
                                binidx.Write(sum.length);
                                binidx.Write(0);
                                //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, (int)sum.pos, (int)sum.length));
                                //Tex.WriteLine(System.String.Format("0x{0:X4} -> 0x{1:X4}", sum.index, index));
                                continue;
                            }
                            //land
                            var bd = bmp.LockBits(
                                new Rectangle(0, 0, bmp.Width, bmp.Height),
                                ImageLockMode.ReadOnly,
                                PixelFormat.Format16bppArgb1555);
                            var line  = (ushort *)bd.Scan0;
                            var delta = bd.Stride >> 1;
                            binidx.Write((int)binmul.BaseStream.Position);                             //lookup
                            var length    = (int)binmul.BaseStream.Position;
                            var x         = 22;
                            var y         = 0;
                            var linewidth = 2;
                            for (var m = 0; m < 22; ++m, ++y, line += delta, linewidth += 2)
                            {
                                --x;
                                var cur = line;
                                for (var n = 0; n < linewidth; ++n)
                                {
                                    binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                                }
                            }
                            x         = 0;
                            linewidth = 44;
                            y         = 22;
                            line      = (ushort *)bd.Scan0;
                            line     += delta * 22;
                            for (var m = 0; m < 22; m++, y++, line += delta, ++x, linewidth -= 2)
                            {
                                var cur = line;
                                for (var n = 0; n < linewidth; n++)
                                {
                                    binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                                }
                            }
                            var start = length;
                            length = (int)binmul.BaseStream.Position - length;
                            binidx.Write(length);
                            binidx.Write(0);
                            bmp.UnlockBits(bd);
                            var s = new CheckSums
                            {
                                pos      = start,
                                length   = length,
                                checksum = checksum,
                                index    = index
                            };
                            //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, start, length));
                            checksumsLand.Add(s);
                        }
                        else
                        {
                            var ms = new MemoryStream();
                            bmp.Save(ms, ImageFormat.Bmp);
                            var       checksum = sha.ComputeHash(ms.ToArray());
                            CheckSums sum;
                            if (compareSaveImagesStatic(checksum, out sum))
                            {
                                binidx.Write(sum.pos);                                 //lookup
                                binidx.Write(sum.length);
                                binidx.Write(0);
                                //Tex.WriteLine(System.String.Format("0x{0:X4} -> 0x{1:X4}", sum.index, index));
                                //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, sum.pos, sum.length));
                                continue;
                            }

                            // art
                            var bd = bmp.LockBits(
                                new Rectangle(0, 0, bmp.Width, bmp.Height),
                                ImageLockMode.ReadOnly,
                                PixelFormat.Format16bppArgb1555);
                            var line  = (ushort *)bd.Scan0;
                            var delta = bd.Stride >> 1;
                            binidx.Write((int)binmul.BaseStream.Position);  //lookup
                            var length = (int)binmul.BaseStream.Position;
                            binmul.Write(1234);                             // header
                            binmul.Write((short)bmp.Width);
                            binmul.Write((short)bmp.Height);
                            var lookup    = (int)binmul.BaseStream.Position;
                            var streamloc = lookup + bmp.Height * 2;
                            var width     = 0;
                            for (var i = 0; i < bmp.Height; ++i)                             // fill lookup
                            {
                                binmul.Write(width);
                            }
                            var X = 0;
                            for (var Y = 0; Y < bmp.Height; ++Y, line += delta)
                            {
                                var cur = line;
                                width = (int)(binmul.BaseStream.Position - streamloc) / 2;
                                binmul.BaseStream.Seek(lookup + Y * 2, SeekOrigin.Begin);
                                binmul.Write(width);
                                binmul.BaseStream.Seek(streamloc + width * 2, SeekOrigin.Begin);
                                var i = 0;
                                var j = 0;
                                X = 0;
                                while (i < bmp.Width)
                                {
                                    i = X;
                                    for (i = X; i <= bmp.Width; ++i)
                                    {
                                        //first pixel set
                                        if (i < bmp.Width)
                                        {
                                            if (cur[i] != 0)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    if (i < bmp.Width)
                                    {
                                        for (j = (i + 1); j < bmp.Width; ++j)
                                        {
                                            //next non set pixel
                                            if (cur[j] == 0)
                                            {
                                                break;
                                            }
                                        }
                                        binmul.Write((short)(i - X));                                         //xoffset
                                        binmul.Write((short)(j - i));                                         //run
                                        for (var p = i; p < j; ++p)
                                        {
                                            binmul.Write((ushort)(cur[p] ^ 0x8000));
                                        }
                                        X = j;
                                    }
                                }
                                binmul.Write((short)0);                                 //xOffset
                                binmul.Write((short)0);                                 //Run
                            }
                            var start = length;
                            length = (int)binmul.BaseStream.Position - length;
                            binidx.Write(length);
                            binidx.Write(0);
                            bmp.UnlockBits(bd);
                            var s = new CheckSums
                            {
                                pos      = start,
                                length   = length,
                                checksum = checksum,
                                index    = index
                            };
                            //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, start, length));
                            checksumsStatic.Add(s);
                        }
                    }
                    memidx.WriteTo(fsidx);
                    memmul.WriteTo(fsmul);
                }
            }
        }
예제 #2
0
파일: Art.cs 프로젝트: EquinoxQNX/TrueUO
        /// <summary>
        ///     Saves mul
        /// </summary>
        /// <param name="path"></param>
        public static unsafe void Save(string path)
        {
            checksumsLand   = new List <CheckSums>();
            checksumsStatic = new List <CheckSums>();
            string idx = Path.Combine(path, "artidx.mul");
            string mul = Path.Combine(path, "art.mul");

            using (
                FileStream fsidx = new FileStream(idx, FileMode.Create, FileAccess.Write, FileShare.Write),
                fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write))
            {
                MemoryStream  memidx = new MemoryStream();
                MemoryStream  memmul = new MemoryStream();
                SHA256Managed sha    = new SHA256Managed();

                using (BinaryWriter binidx = new BinaryWriter(memidx), binmul = new BinaryWriter(memmul))
                {
                    for (int index = 0; index < GetIdxLength(); index++)
                    {
                        Files.FireFileSaveEvent();
                        if (m_Cache[index] == null)
                        {
                            if (index < 0x4000)
                            {
                                m_Cache[index] = GetLand(index);
                            }
                            else
                            {
                                m_Cache[index] = GetStatic(index - 0x4000, false);
                            }
                        }
                        Bitmap bmp = m_Cache[index];
                        if ((bmp == null) || (m_Removed[index]))
                        {
                            binidx.Write(-1); // lookup
                            binidx.Write(0);  // length
                            binidx.Write(-1); // extra
                        }
                        else if (index < 0x4000)
                        {
                            MemoryStream ms = new MemoryStream();
                            bmp.Save(ms, ImageFormat.Bmp);
                            byte[]    checksum = sha.ComputeHash(ms.ToArray());
                            CheckSums sum;
                            if (compareSaveImagesLand(checksum, out sum))
                            {
                                binidx.Write(sum.pos); //lookup
                                binidx.Write(sum.length);
                                binidx.Write(0);
                                continue;
                            }
                            //land
                            BitmapData bd = bmp.LockBits(
                                new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, Settings.PixelFormat);
                            ushort *line  = (ushort *)bd.Scan0;
                            int     delta = bd.Stride >> 1;
                            binidx.Write((int)binmul.BaseStream.Position); //lookup
                            int length    = (int)binmul.BaseStream.Position;
                            int x         = 22;
                            int y         = 0;
                            int linewidth = 2;
                            for (int m = 0; m < 22; ++m, ++y, line += delta, linewidth += 2)
                            {
                                --x;
                                ushort *cur = line;
                                for (int n = 0; n < linewidth; ++n)
                                {
                                    binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                                }
                            }
                            x         = 0;
                            linewidth = 44;
                            y         = 22;
                            line      = (ushort *)bd.Scan0;
                            line     += delta * 22;
                            for (int m = 0; m < 22; m++, y++, line += delta, ++x, linewidth -= 2)
                            {
                                ushort *cur = line;
                                for (int n = 0; n < linewidth; n++)
                                {
                                    binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                                }
                            }
                            int start = length;
                            length = (int)binmul.BaseStream.Position - length;
                            binidx.Write(length);
                            binidx.Write(0);
                            bmp.UnlockBits(bd);
                            CheckSums s = new CheckSums
                            {
                                pos      = start,
                                length   = length,
                                checksum = checksum,
                                index    = index
                            };
                            checksumsLand.Add(s);
                        }
                        else
                        {
                            MemoryStream ms = new MemoryStream();
                            bmp.Save(ms, ImageFormat.Bmp);
                            byte[]    checksum = sha.ComputeHash(ms.ToArray());
                            CheckSums sum;
                            if (compareSaveImagesStatic(checksum, out sum))
                            {
                                binidx.Write(sum.pos); //lookup
                                binidx.Write(sum.length);
                                binidx.Write(0);
                                continue;
                            }

                            // art
                            BitmapData bd = bmp.LockBits(
                                new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, Settings.PixelFormat);
                            ushort *line  = (ushort *)bd.Scan0;
                            int     delta = bd.Stride >> 1;
                            binidx.Write((int)binmul.BaseStream.Position); //lookup
                            int length = (int)binmul.BaseStream.Position;
                            binmul.Write(1234);                            // header
                            binmul.Write((short)bmp.Width);
                            binmul.Write((short)bmp.Height);
                            int lookup    = (int)binmul.BaseStream.Position;
                            int streamloc = lookup + bmp.Height * 2;
                            int width     = 0;
                            for (int i = 0; i < bmp.Height; ++i) // fill lookup
                            {
                                binmul.Write(width);
                            }
                            int X = 0;
                            for (int Y = 0; Y < bmp.Height; ++Y, line += delta)
                            {
                                ushort *cur = line;
                                width = (int)(binmul.BaseStream.Position - streamloc) / 2;
                                binmul.BaseStream.Seek(lookup + Y * 2, SeekOrigin.Begin);
                                binmul.Write(width);
                                binmul.BaseStream.Seek(streamloc + width * 2, SeekOrigin.Begin);
                                int i = 0;
                                int j = 0;
                                X = 0;
                                while (i < bmp.Width)
                                {
                                    i = X;
                                    for (i = X; i <= bmp.Width; ++i)
                                    {
                                        //first pixel set
                                        if (i < bmp.Width)
                                        {
                                            if (cur[i] != 0)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    if (i < bmp.Width)
                                    {
                                        for (j = (i + 1); j < bmp.Width; ++j)
                                        {
                                            //next non set pixel
                                            if (cur[j] == 0)
                                            {
                                                break;
                                            }
                                        }
                                        binmul.Write((short)(i - X)); //xoffset
                                        binmul.Write((short)(j - i)); //run
                                        for (int p = i; p < j; ++p)
                                        {
                                            binmul.Write((ushort)(cur[p] ^ 0x8000));
                                        }
                                        X = j;
                                    }
                                }
                                binmul.Write((short)0); //xOffset
                                binmul.Write((short)0); //Run
                            }
                            int start = length;
                            length = (int)binmul.BaseStream.Position - length;
                            binidx.Write(length);
                            binidx.Write(0);
                            bmp.UnlockBits(bd);
                            CheckSums s = new CheckSums
                            {
                                pos      = start,
                                length   = length,
                                checksum = checksum,
                                index    = index
                            };
                            checksumsStatic.Add(s);
                        }
                    }
                    memidx.WriteTo(fsidx);
                    memmul.WriteTo(fsmul);
                }
            }
        }
예제 #3
0
파일: Art.cs 프로젝트: UOAccess/UOFiddler
        /// <summary>
        /// Saves mul
        /// </summary>
        /// <param name="path"></param>
        public static unsafe void Save(string path)
        {
            _checksumsLand   = new List <CheckSums>();
            _checksumsStatic = new List <CheckSums>();

            string idx = Path.Combine(path, "artidx.mul");
            string mul = Path.Combine(path, "art.mul");

            using (var fsidx = new FileStream(idx, FileMode.Create, FileAccess.Write, FileShare.Write))
                using (var fsmul = new FileStream(mul, FileMode.Create, FileAccess.Write, FileShare.Write))
                {
                    var memidx = new MemoryStream();
                    var memmul = new MemoryStream();
                    //var sha = new SHA256Managed();
                    //StreamWriter Tex = new StreamWriter(new FileStream("d:/artlog.txt", FileMode.Create, FileAccess.ReadWrite));

                    using (var binidx = new BinaryWriter(memidx))
                        using (var binmul = new BinaryWriter(memmul))
                        {
                            for (int index = 0; index < GetIdxLength(); index++)
                            {
                                Files.FireFileSaveEvent();
                                if (_cache[index] == null)
                                {
                                    if (index < 0x4000)
                                    {
                                        _cache[index] = GetLand(index);
                                    }
                                    else
                                    {
                                        _cache[index] = GetStatic(index - 0x4000, false);
                                    }
                                }

                                Bitmap bmp = _cache[index];
                                if (bmp == null || _removed[index])
                                {
                                    binidx.Write(-1); // lookup
                                    binidx.Write(0);  // length
                                    binidx.Write(-1); // extra
                                    //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, (int)-1, (int)-1));
                                }
                                else if (index < 0x4000)
                                {
                                    byte[] checksum = bmp.ToArray(PixelFormat.Format16bppArgb1555).ToSha256();
                                    if (CompareSaveImagesLand(checksum, out CheckSums sum))
                                    {
                                        binidx.Write(sum.pos); //lookup
                                        binidx.Write(sum.length);
                                        binidx.Write(0);
                                        //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, (int)sum.pos, (int)sum.length));
                                        //Tex.WriteLine(System.String.Format("0x{0:X4} -> 0x{1:X4}", sum.index, index));
                                        continue;
                                    }

                                    //land
                                    BitmapData bd = bmp.LockBits(
                                        new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly,
                                        PixelFormat.Format16bppArgb1555);
                                    var line  = (ushort *)bd.Scan0;
                                    int delta = bd.Stride >> 1;
                                    binidx.Write((int)binmul.BaseStream.Position); //lookup
                                    var length    = (int)binmul.BaseStream.Position;
                                    int x         = 22;
                                    int y         = 0;
                                    int lineWidth = 2;
                                    for (int m = 0; m < 22; ++m, ++y, line += delta, lineWidth += 2)
                                    {
                                        --x;
                                        ushort *cur = line;
                                        for (int n = 0; n < lineWidth; ++n)
                                        {
                                            binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                                        }
                                    }

                                    x         = 0;
                                    lineWidth = 44;
                                    y         = 22;
                                    line      = (ushort *)bd.Scan0;
                                    line     += delta * 22;
                                    for (int m = 0; m < 22; m++, y++, line += delta, ++x, lineWidth -= 2)
                                    {
                                        ushort *cur = line;
                                        for (int n = 0; n < lineWidth; n++)
                                        {
                                            binmul.Write((ushort)(cur[x + n] ^ 0x8000));
                                        }
                                    }

                                    int start = length;
                                    length = (int)binmul.BaseStream.Position - length;
                                    binidx.Write(length);
                                    binidx.Write(0);
                                    bmp.UnlockBits(bd);
                                    CheckSums s = new CheckSums
                                    {
                                        pos = start, length = length, checksum = checksum, index = index
                                    };
                                    //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, start, length));
                                    _checksumsLand.Add(s);
                                }
                                else
                                {
                                    byte[] checksum = bmp.ToArray(PixelFormat.Format16bppArgb1555).ToSha256();
                                    if (CompareSaveImagesStatic(checksum, out CheckSums sum))
                                    {
                                        binidx.Write(sum.pos); //lookup
                                        binidx.Write(sum.length);
                                        binidx.Write(0);
                                        //Tex.WriteLine(System.String.Format("0x{0:X4} -> 0x{1:X4}", sum.index, index));
                                        //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, sum.pos, sum.length));
                                        continue;
                                    }

                                    // art
                                    BitmapData bd    = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format16bppArgb1555);
                                    var        line  = (ushort *)bd.Scan0;
                                    int        delta = bd.Stride >> 1;
                                    binidx.Write((int)binmul.BaseStream.Position); // lookup
                                    var length = (int)binmul.BaseStream.Position;
                                    binmul.Write(1234);                            // header
                                    binmul.Write((short)bmp.Width);
                                    binmul.Write((short)bmp.Height);
                                    var lookup    = (int)binmul.BaseStream.Position;
                                    int streamLoc = lookup + (bmp.Height * 2);
                                    int width     = 0;
                                    for (int i = 0; i < bmp.Height; ++i) // fill lookup
                                    {
                                        binmul.Write(width);
                                    }

                                    for (int y = 0; y < bmp.Height; ++y, line += delta)
                                    {
                                        ushort *cur = line;
                                        width = (int)(binmul.BaseStream.Position - streamLoc) / 2;
                                        binmul.BaseStream.Seek(lookup + (y * 2), SeekOrigin.Begin);
                                        binmul.Write(width);
                                        binmul.BaseStream.Seek(streamLoc + (width * 2), SeekOrigin.Begin);
                                        int i = 0;
                                        int x = 0;
                                        while (i < bmp.Width)
                                        {
                                            i = x;
                                            for (i = x; i <= bmp.Width; ++i)
                                            {
                                                // first pixel set
                                                if (i < bmp.Width)
                                                {
                                                    if (cur[i] != 0)
                                                    {
                                                        break;
                                                    }
                                                }
                                            }

                                            if (i >= bmp.Width)
                                            {
                                                continue;
                                            }

                                            int j;
                                            for (j = i + 1; j < bmp.Width; ++j)
                                            {
                                                // next non set pixel
                                                if (cur[j] == 0)
                                                {
                                                    break;
                                                }
                                            }

                                            binmul.Write((short)(i - x)); // xOffset
                                            binmul.Write((short)(j - i)); // run
                                            for (int p = i; p < j; ++p)
                                            {
                                                binmul.Write((ushort)(cur[p] ^ 0x8000));
                                            }

                                            x = j;
                                        }

                                        binmul.Write((short)0); // xOffset
                                        binmul.Write((short)0); // Run
                                    }

                                    int start = length;
                                    length = (int)binmul.BaseStream.Position - length;
                                    binidx.Write(length);
                                    binidx.Write(0);
                                    bmp.UnlockBits(bd);
                                    var s = new CheckSums {
                                        pos = start, length = length, checksum = checksum, index = index
                                    };
                                    //Tex.WriteLine(System.String.Format("0x{0:X4} : 0x{1:X4} 0x{2:X4}", index, start, length));
                                    _checksumsStatic.Add(s);
                                }
                            }

                            memidx.WriteTo(fsidx);
                            memmul.WriteTo(fsmul);
                        }
                }
        }