FSN File Parsing (C #)

Source: Internet
Author: User

  public class fsnbiznet    {        private static int count;      &NBS P public static int parseint (ilist<string> list)         {            int value = Convert.ToInt32 (List[count + 1] + List[count], 2);            count + = 2;            return value;       }        public static St Ring parsestring (ilist<string> list)         {            string VA Lue = List[count + 3] + List[count + 2] + List[count + 1] + list[count];            count + = 4;            return value;       }        Public Static list<string> Readfiletobit (string filepath)         {          &N Bsp FileStream @in = New FileStream (filepath, FileMode.Open);            list<string> List = new List<s Tring> ();            long left = @in. length;//file size             byte[] buffer = new byte[1024];          & nbsp int start = 0;//Read position             int length = 0; Actual return result length             while (left > 0)             {  & nbsp             @in. Position = start;                length = 0;          &NB Sp     if (left < buffer. Length)                     length = @in. Read (buffer, 0, Convert.ToInt32 (left));                else      &N Bsp             length = @in. Read (buffer, 0, buffer. Length);                if (length = = 0)                 {                    break;        &NB Sp      }                start = start + length;                left = left-length;                for (int i = 0; i < length; i++)                 {                &NBSP ;   string s = convert.tostring (Buffer[i] | 2);                  &NBS P s = s.substring (s.length-8);                    list. ADD (s);               }            }            @in. Close ();            return list;       }        Pub Lic static Snohead gethead (ilist<string> list)         {            Count = 0;            fsnbiznet f = new fsnbiznet ();          &NBS P Snohead sh = new Fsnbiznet.snohead (f);            int[] Headstart = new int[4];            for (int i = 0; i < 4; i++)             {                Headstart[i] = parseint (list);           }            SH. Headstart = headstart;            int[] headstring = new int[6];            for (int i = 0; i < 6; i++)     &NBSP;       {                Headstring[i] = parseint (list);           }            SH. headstring = headstring;            Long counter = parseint (list) + (parseint (list) << 8);            SH. Counter = counter;            int[] headend = new int[4];            for (int i = 0; i < 4; i++)             {                Headend[i] = parseint (list);           }          &N Bsp Sh. Headend = headend;            return sh;       }      &N Bsp public static IDictionary getsnoexpimg (ilist<string> list)         {        & nbsp &nbsp Count = 0;            IDictionary map = new Hashtable ();          & nbsp Set Date time             int data = parseint (list);          INT Time = parseint (list);            int y = data >> 9;        &NBSP ;   int m = (data-(Y << 9)) >> 5;            INT d = data-(y << 9) -(M << 5);            int hh = time >> 11;          &N Bsp int mm = (Time-(HH << one)) >> 5;            int ss = (Time-(HH << 11) -(mm << 5)) << 1;            map["DateTime"] = y + 1980 + "-" + M + "-" + D + " "+ hh +": "+ mm +": "+ ss;           //Set currency True, false, residual and old currency mark         &NBSP ; &nbSp map["Tfflag"] = parseint (list);           //Set currency error codes (3)             String errorCode = "";            for (int i = 0; I < 3; i++)             {                INT code = parseint (list);                if (Code < && code > 0)     &NBSP ;           {                    ErrorCode + = Cod E + ",";               }           }            if ("1". Equals (map["Tfflag"))             {                E Rrorcode = errorcode.substring (0, Errorcode.lastindexof (","));           }    &N Bsp &nbSp     else            {                Error Code = "0";           }            map["ErrorCode"] = Errorco de;           //Set currency flag (4)             String moneyflag = "";             for (int i = 0; i < 4; i++)             {                INT flag = parseint (list);            &NBSP ;   IF (flag! = 0)                 {            &N Bsp       Moneyflag + = (char) flag;               }           }            map["moneyflag"] = moneyflag;            Set year or version number flags             int ver = parseint (list);            if (ver = 0)             {                ver = 199 0;           }            if (ver = 1)       & nbsp     {                ver = 1999;          &NBSP ; }            if (ver = 2)             {      &N Bsp         ver = 2005;           }          &NBSP ; if (ver = 9999)             {                ver = 0 ;           }            map["Ver"] = ver;    &NBSP ;     /Set currency             map["valuta"] = parseint (list);           //Setting the number of crown digits             map["CharNum"] = parseint (list);      &NB Sp    /Set Crown font size (12)             String no = "";          &NB Sp for (int i = 0; i < i++)             {                int No = parseint (list);                if (no! = 0)       & nbsp         {                    NO + = (char) no;  & nbsp            }           }          & nbsp map["Sno"] = no;           //Set up implement number (24)             string Machinesno = "";            for (int i = 0; I < 24; i++)             {                int msno = parseint (list);                if (Msno! = 0)             &NB Sp   {                    Machinesno + = (char) msno;    &NBSP ;          }           }            m ap["Machinesno"] = machinesno;           //Set Crown font reserved word           &NBS P map["Reserve1"] = parseint (list);            return map;       }        public static Bitmap getsnoimg (ilist<string> list)         {    &N Bsp       count = 0;    &nbsp       int num = parseint (list);            int height = parseint (list);            int width = parseint (list);            int Reserve2 = PA Rseint (list);           //Create an image buffer based on read information             Brush BR Uch = brushes.white;            BITMAP image = new Bitmap (width * num, height, pixelformat.f ORMAT32BPPRGB);            System.Drawing.Graphics g = graphics.fromimage (image);  & nbsp         G.fillrectangle (Bruch, 0, 0, Width * num, height);            G. Dispose ();            int i = 0;            while (list. Count-count > 0 && i < width * num)             {               string s = parsestring (list);                for (int j = 0; J < height && J < S.length; J + +)                 {                &NBSP ;   if (s[j] = = ' 1 ')                     {                         int colorvalue =convert.toint32 (0x000000);    &nbs P                    image. SetPixel (i, J, Color.FromArgb (ColorValue));                   }  & nbsp            }                i++;    &NBSP ;      }            return image;       }    &N Bsp   public static List<IDictionary> readFile (string path)         {           //Bit-lis t            list<string> listbit = readfiletobit (path);        &N Bsp  /Header files             Snohead sh = gethead (listbit.getrange (0, 32-0));    &NBSP ;      //Crown size Information Bar             long counter = sh. counter;           //based on the Crown font header file to determine whether there is an image, to obtain a Crown font information contains the byte number             INT size = sh. HEADSTRING[2]! = 0x2D? 1644:100;            if (counter * size + = = Listbit.count)             {               //string ImagePath = Thread.CurrentThread.ContextCl Assloader.getresource (""). Path.substring (1). Replace ("%20", "");                StrinG ImagePath = AppDomain.CurrentDomain.BaseDirectory.Substring (0). Replace ("%20", "");                ImagePath = Path.Combine (ImagePath, "image"); &N Bsp               list<idictionary> List = new list<idictionary> ();  &nbsp ;             for (int i = 0; i < counter; i++)             &N Bsp   {                   //listbit.toarray () .      &NB Sp             IDictionary map = getsnoexpimg (Listbit.getrange (i * size + +, I * size + 132- (i * size + 32)));                     if (size! =)           & nbsp         {                        Bitmap im Agesno = getsnoimg (Listbit.getrange (i * s)Ize + PPI, (i + 1) * Size-(i * size +));                    &NBSP ;   Imagesno.save (Path.Combine (Imagepath,i + ". bmp"), imageformat.bmp);            & nbsp           map["imagesno"] = "image/" + i + ". bmp";            &NBSP ;      }                    else      &NBSP ;             {                      &N Bsp map["Imagesno"] = null;                   }                    list. ADD (map);               }                Return list;           }        &NBSP   return null;       }        public class snohead      &NBSP ; {            private readonly fsnbiznet outerinstance;          &NB Sp Public Snohead (fsnbiznet outerinstance)             {          &NBSP ;     this.outerinstance = outerinstance;           }        &N Bsp   Internal int[] headstart;            internal int[] headstring;      & nbsp     Internal long counter;            internal int[] headend_renamed;            public virtual int[] headstart            {                get                {      &NBSP ;            return headstart;               }                set                {  &nbsp ;                 This.headstart = value;            & nbsp  }           }            public virtual int[] Headstri ng            {                get    &NBS P           {                    return Headstrin g;               }                SET&NBS P               {                    TH Is.headstring = value;               }           }  &NB Sp         public virtual long counter            {      &NB Sp         get                {                    return counter;               }                set                {                    This.counter = value;              &N Bsp }           }            public virtual int[] headend  & nbsp         {                get          &nbsP     {                    return headend_renamed;               }                set                {                    headend_renamed = value;               }           }       }   }

FSN File Parsing (C #)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.