Exemplo n.º 1
0
 public int CalcCRC()
 {
     if (Buffer == null)
     {
         return(0);
     }
     return(CRCCalc.Calc(Buffer));
 }
Exemplo n.º 2
0
        public static SharedImage CreateForResource(string resourceID)
        {
            SharedImage image = new SharedImage();

            image.m_ResourceName = resourceID;
            // Note that the CRC must NOT use string.GetHashCode because that can vary between machines.  The value is stored in the data and must be reproducible
            image.CRC = CRCCalc.Calc(System.Text.Encoding.Unicode.GetBytes(resourceID));
            return(image);
        }
Exemplo n.º 3
0
 /// <summary>it is assumed that the document has already been checked for any duplicates</summary>
 public static SharedImage CreateFromFile(string file, int CRC = 0)
 {
     if (CRC == 0)
     {
         CRC = CRCCalc.Calc(file);
     }
     return(new SharedImage {
         m_Image = new MemoryImage(file), CRC = CRC
     });
 }
Exemplo n.º 4
0
        public static SharedResource CreateFromBuffer(byte[] buffer, string fileExtension)
        {
            Debug.Assert(fileExtension.StartsWith("."));
            SharedResource resource = new SharedResource();

            resource.Buffer   = buffer;
            resource.CRC      = CRCCalc.Calc(resource.Buffer);
            resource.Filename = "auto" + fileExtension;
            return(resource);
        }
Exemplo n.º 5
0
        public static SharedResource CreateFromFile(string file, int CRC = 0)
        {
            SharedResource resource = new SharedResource();

            resource.Buffer   = File.ReadAllBytes(file);
            resource.Filename = Path.GetFileName(file);
            if (CRC == 0)
            {
                CRC = CRCCalc.Calc(resource.Buffer);
            }
            resource.CRC = CRC;
            return(resource);
        }
Exemplo n.º 6
0
        public static SharedResource CreateFromStream(Stream strm, string fileExtension, int intCRC = 0)
        {
            Debug.Assert(fileExtension.StartsWith("."));
            SharedResource resource = new SharedResource();
            int            length   = (int)strm.Length;

            strm.Seek(0, SeekOrigin.Begin);
            resource.Buffer = new byte[length - 1 + 1];
            strm.Read(resource.Buffer, 0, length);
            // we don't keep the original stream, just the buffer we have filled from it
            if (intCRC == 0)
            {
                intCRC = CRCCalc.Calc(resource.Buffer);
            }
            resource.CRC      = intCRC;
            resource.Filename = "auto" + fileExtension;
            return(resource);
        }