Example #1
0
        public static void FileCopy(string oldName, string newName, bool skipIfNoChange, bool deleteBom, bool useTimeStampToCheckNoChange)
        {
            string tmp1 = InnerFilePath(oldName);
            string tmp2 = InnerFilePath(newName);

            if (useTimeStampToCheckNoChange && skipIfNoChange)
            {
                DateTime dt1, dt2;

                try
                {
                    dt1 = Directory.GetLastWriteTimeUtc(tmp1);
                    dt2 = Directory.GetLastWriteTimeUtc(tmp2);

                    TimeSpan ts = dt2 - dt1;
                    if (ts.TotalSeconds >= -5.0)
                    {
                        return;
                    }
                }
                catch
                {
                }
            }

            if (skipIfNoChange || deleteBom)
            {
                byte[] srcData  = File.ReadAllBytes(tmp1);
                byte[] destData = new byte[0];
                bool   changed  = true;
                int    bomSize;

                Str.GetEncoding(srcData, out bomSize);
                if (bomSize >= 1)
                {
                    srcData = Util.ExtractByteArray(srcData, bomSize, srcData.Length - bomSize);
                }

                if (skipIfNoChange)
                {
                    try
                    {
                        FileStream fs   = File.OpenRead(tmp2);
                        long       size = 0xffffffff;
                        try
                        {
                            size = fs.Length;
                        }
                        finally
                        {
                            fs.Close();
                        }

                        if (size == srcData.Length || srcData.Length == 0)
                        {
                            destData = File.ReadAllBytes(tmp2);
                        }
                    }
                    catch
                    {
                    }

                    if (Util.CompareByte(srcData, destData))
                    {
                        changed = false;
                    }
                }

                if (changed)
                {
                    File.WriteAllBytes(tmp2, srcData);
                    CopyFileTimestamp(tmp2, tmp1);
                }
            }
            else
            {
                File.Copy(tmp1, tmp2, true);
            }
        }
Example #2
0
        public bool Verify(byte[] data, byte[] sign)
        {
            byte[] sign2 = Sign(data);

            return(Util.CompareByte(sign, sign2));
        }
Example #3
0
        void init(string filename)
        {
            filename = IO.InnerFilePath(filename);
            string filenameOnly = Path.GetFileName(filename);
            string filenameAlt  = Path.Combine(Path.GetDirectoryName(filename), "_" + filenameOnly);

            try
            {
                IO.FileReplaceRename(filenameAlt, filename);
            }
            catch
            {
            }

            list = new Dictionary <string, HamCoreEntry>();

            try
            {
                hamcore_io = IO.FileOpen(filename);
            }
            catch
            {
                return;
            }

            try
            {
                byte[] header  = hamcore_io.Read(HamcoreHeaderSize);
                byte[] header2 = Str.AsciiEncoding.GetBytes(HamcoreHeaderData);
                if (header == null || Util.CompareByte(header, header2) == false)
                {
                    throw new SystemException();
                }

                uint   num = 0;
                byte[] buf = hamcore_io.Read(Util.SizeOfInt32);
                num = Util.ByteToUInt(buf);
                uint i;
                for (i = 0; i < num; i++)
                {
                    uint str_size;

                    buf      = hamcore_io.Read(Util.SizeOfInt32);
                    str_size = Util.ByteToUInt(buf);
                    if (str_size >= 1)
                    {
                        str_size--;
                    }

                    byte[] str_data = hamcore_io.Read((int)str_size);
                    string tmp      = Str.ShiftJisEncoding.GetString(str_data);

                    HamCoreEntry c = new HamCoreEntry();
                    c.FileName = tmp;

                    buf    = hamcore_io.Read(Util.SizeOfInt32);
                    c.Size = Util.ByteToUInt(buf);

                    buf = hamcore_io.Read(Util.SizeOfInt32);
                    c.SizeCompressed = Util.ByteToUInt(buf);

                    buf      = hamcore_io.Read(Util.SizeOfInt32);
                    c.Offset = Util.ByteToUInt(buf);

                    list.Add(c.FileName.ToUpper(), c);
                }
            }
            catch
            {
                hamcore_io.Close();
            }
        }