예제 #1
0
파일: HID.cs 프로젝트: xbox3601112/J-Runner
 private static bool verify(ref ProgressBar pb)
 {
     try
     {
         string   filename = variables.filename1;
         FileInfo fl       = new FileInfo(filename);
         int      filesize = (int)fl.Length;
         byte[]   file     = File.ReadAllBytes(filename);
         if (file[0] != 0x3A)
         {
             Console.WriteLine("Bad file"); return(false);
         }
         byte[] length  = new byte[2];
         byte[] address = new byte[4];
         byte[] record  = new byte[2];
         byte[] line, write, offset;
         int    i = 0, len = 0, add = 0, rec = 0;
         while (!variables.escapeloop)
         {
             length  = Oper.returnportion(file, i + 1, 2);
             address = Oper.returnportion(file, i + 3, 4);
             record  = Oper.returnportion(file, i + 7, 2);
             len     = Convert.ToInt32((ASCIIEncoding.ASCII.GetString(length)), 16);
             rec     = Convert.ToInt32((ASCIIEncoding.ASCII.GetString(record)), 16);
             add     = Convert.ToInt32((ASCIIEncoding.ASCII.GetString(address)), 16);
             offset  = Oper.StringToByteArray(ASCIIEncoding.ASCII.GetString(address));
             Array.Reverse(offset);
             line  = Oper.returnportion(file, i + 9, len * 2);
             write = Oper.StringToByteArray(ASCIIEncoding.ASCII.GetString(line));
             if ((add >= 0x800) && (add < 0x6000) && (rec == 0))
             {
                 byte[] send = new byte[0x3F];
                 send[1] = 0x5;
                 send[6] = 0x10;
                 Buffer.BlockCopy(offset, 0, send, 3, 2);
                 pb.Value = ((i * pb.Maximum) / filesize);
                 re       = new HidReport(0x3F, new HidDeviceData(send, HidDeviceData.ReadStatus.Success));
                 byte[] returnb = null;
                 if (!_selectedDevice.WriteReport(re, 5000))
                 {
                     Console.Write("X");
                 }
                 else
                 {
                     re      = _selectedDevice.ReadReport(5000);
                     returnb = re.Data;
                 }
                 if (!Oper.ByteArrayCompare(Oper.returnportion(returnb, 6, write.Length), write))
                 {
                     //if (comboBox1.Text == "2") Console.WriteLine("Data: {0:X}", ByteArrayToString(datab));
                     if (variables.debugme)
                     {
                         Console.WriteLine("Return: {0:X}", Oper.ByteArrayToString(returnb));
                     }
                     if (variables.debugme)
                     {
                         Console.WriteLine("Data: {0:X}", Oper.ByteArrayToString(Oper.returnportion(returnb, 6, 0x10)));
                     }
                     if (variables.debugme)
                     {
                         Console.WriteLine("File: {0:X}", Oper.ByteArrayToString(write));
                     }
                     Console.Write("x");
                 }
                 else if (i % 8 == 0)
                 {
                     Console.Write(".");
                 }
                 Thread.Sleep(0x5);
             }
             if (rec == 0x01)
             {
                 break;
             }
             i = i + 2 + 4 + 2 + len + len + 2 + 2 + 1;
             if (file[i] != 0x3A)
             {
                 break;
             }
         }
         variables.escapeloop = false;
         return(true);
     }
     catch (Exception ex) { Console.WriteLine(ex.ToString()); return(false); }
 }