protected void OnNVItemsStatusChanged(NVItemsStatusEventArgs e)
        {
            NVItemsStatusEventHandler nVItemsStatusChangedEvent = this.NVItemsStatusChangedEvent;

            if (nVItemsStatusChangedEvent != null)
            {
                nVItemsStatusChangedEvent(e);
            }
        }
        private void ProcessCommandQueue(AsyncOperation asyncOp)
        {
            this._isBusy        = true;
            this._commandOutput = new ArrayList();
            long      count          = this.GetCount();
            long      num2           = 0L;
            long      position       = 0L;
            string    consoleTX      = string.Empty;
            string    consoleRX      = string.Empty;
            string    consoleRXASCII = string.Empty;
            Exception exc            = null;

            try
            {
                object syncRoot = this.cmdQueue.SyncRoot;
                ObjectFlowControl.CheckForSyncLockOnValueType(syncRoot);
                lock (syncRoot)
                {
                    while (this.cmdQueue.Count != 0)
                    {
                        if (this.Cancelled())
                        {
                            this.CompletionMethod(null, true, asyncOp);
                            return;
                        }
                        Command command = (Command)this.cmdQueue.Dequeue();
                        this._qcdmCmd.Add(command.CurrentQCDMCommand);
                        this._nvCmd.Add(command.CurrentNVItem);
                        if (!command.TransmitTX(this._instance, asyncOp))
                        {
                            throw new Exception("Phone connection has been lost!");
                        }
                        object objectValue = RuntimeHelpers.GetObjectValue(command.Decode());
                        if (command.BytesRX.Length == 0x88)
                        {
                            this._errorResponse.Add((Qcdm.NV_Response)command.BytesRX[0x83]);
                        }
                        else if (command.BytesRX.Length == 0x89)
                        {
                            this._errorResponse.Add((Qcdm.NV_Response)command.BytesRX[0x84]);
                        }
                        else if (command.BytesRX.Length < 0x88)
                        {
                            this._errorResponse.Add((Qcdm.NV_Response)command.BytesRX[0]);
                        }
                        if (objectValue == null)
                        {
                            throw new Exception("Error decoding command output!");
                        }
                        this._commandOutput.Add(RuntimeHelpers.GetObjectValue(objectValue));
                        if (!this._disableLogging && !string.IsNullOrEmpty(command.ConsoleOutput))
                        {
                            consoleTX      = ConversionUtils.FormatHexStr(ConversionUtils.BytesToHexString(command.BytesTX));
                            consoleRX      = ConversionUtils.FormatHexStr(ConversionUtils.BytesToHexString(command.BytesRX));
                            consoleRXASCII = ConversionUtils.GetASCIIString(command.BytesRX);
                        }
                        position += 1L;
                        CommandQueueProgressChangedEventArgs arg = new CommandQueueProgressChangedEventArgs(command.ConsoleOutput, consoleTX, consoleRX, consoleRXASCII, (int)command.CurrentNVItem, (int)position, (int)count, (int)Math.Round((double)((((float)position) / ((float)count)) * 100f)), RuntimeHelpers.GetObjectValue(asyncOp.UserSuppliedState));
                        asyncOp.Post(this.onProgressReportDelegate, arg);
                    }
                }
                if (this._chkNVItems)
                {
                    position = 0L;
                    long   badParamNVItems = 0L;
                    long   badSecNVItems   = 0L;
                    long   inactiveNVItems = 0L;
                    long   okayNVItems     = 0L;
                    object expression      = this.cmdNVQueue.SyncRoot;
                    ObjectFlowControl.CheckForSyncLockOnValueType(expression);
                    lock (expression)
                    {
                        IEnumerator enumerator;
                        try
                        {
                            enumerator = this.cmdNVQueue.GetEnumerator();
                            while (enumerator.MoveNext())
                            {
                                byte    num6;
                                Command current = (Command)enumerator.Current;
                                if (this.Cancelled())
                                {
                                    this.CompletionMethod(null, true, asyncOp);
                                    return;
                                }
                                if (current.BytesRX.Length == 0x88)
                                {
                                    num6 = current.BytesRX[0x83];
                                }
                                else if (current.BytesRX.Length == 0x89)
                                {
                                    num6 = current.BytesRX[0x84];
                                }
                                else if (current.BytesRX.Length < 0x88)
                                {
                                    num6 = current.BytesRX[0];
                                }
                                if (((num6 == 20) | (num6 == 5)) | (num6 == 6))
                                {
                                    current.ErrorResponse = (Qcdm.NV_Response)num6;
                                    num2 += 1L;
                                }
                            }
                        }
                        finally
                        {
                            if (enumerator is IDisposable)
                            {
                                (enumerator as IDisposable).Dispose();
                            }
                        }
                    }
                    object obj5 = this.cmdNVQueue.SyncRoot;
                    ObjectFlowControl.CheckForSyncLockOnValueType(obj5);
                    lock (obj5)
                    {
                        IEnumerator enumerator2;
                        if (string.IsNullOrEmpty(this._fileName))
                        {
                            throw new FileNotFoundException();
                        }
                        StreamWriter writer = new StreamWriter(this.FileName, false);
                        writer.Write("[NV items]\r\n");
                        writer.Write(("[Complete items - " + ((count - num2)).ToString() + ", Items size - 128]") + "\r\n\r\n");
                        try
                        {
                            enumerator2 = this.cmdNVQueue.GetEnumerator();
                            while (enumerator2.MoveNext())
                            {
                                string        str6;
                                Command       command3 = (Command)enumerator2.Current;
                                List <string> list     = new List <string>();
                                if (command3.BytesRX[0] == 20)
                                {
                                    str6 = ConversionUtils.BytesToHexString(command3.BytesTX).Substring(2, 4);
                                }
                                else
                                {
                                    str6 = ConversionUtils.BytesToHexString(command3.BytesRX).Substring(2, 4);
                                }
                                string s    = ConversionUtils.ReverseHex(str6).Replace(" ", "");
                                long   num9 = long.Parse(s, NumberStyles.HexNumber);
                                if (command3.ErrorResponse == Qcdm.NV_Response.NV_ERR_BAD_PARAM)
                                {
                                    writer.Write((num9.ToString("d5") + " (0x" + s + ")   -   Parameter bad") + "\r\n\r\n");
                                    badParamNVItems += 1L;
                                }
                                else if (command3.ErrorResponse == Qcdm.NV_Response.NV_ERR_BAD_SECURITY_MODE)
                                {
                                    writer.Write((num9.ToString("d5") + " (0x" + s + ")   -   Access denied") + "\r\n\r\n");
                                    badSecNVItems += 1L;
                                }
                                else if (command3.ErrorResponse == Qcdm.NV_Response.NV_ERR_INACTIVE_NV_ITEM)
                                {
                                    writer.Write((num9.ToString("d5") + " (0x" + s + ")   -   Inactive item") + "\r\n\r\n");
                                    inactiveNVItems += 1L;
                                }
                                else
                                {
                                    string str11 = ConversionUtils.BytesToHexString(command3.BytesRX).Substring(6, 0x100);
                                    writer.Write((num9.ToString("d5") + " (0x" + s + ")   -   OK") + "\r\n");
                                    writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0, 0x20)) + "\r\n");
                                    writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0x20, 0x20)) + "\r\n");
                                    writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0x40, 0x20)) + "\r\n");
                                    writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0x60, 0x20)) + "\r\n");
                                    writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0x40, 0x20)) + "\r\n");
                                    writer.Write(ConversionUtils.FormatHexStr(str11.Substring(80, 0x20)) + "\r\n");
                                    writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0x60, 0x20)) + "\r\n");
                                    writer.Write(ConversionUtils.FormatHexStr(str11.Substring(0x80, 0x20)) + "\r\n\r\n");
                                    okayNVItems += 1L;
                                }
                                position += 1L;
                                NVItemsStatusEventArgs args2 = new NVItemsStatusEventArgs(position, badParamNVItems, badSecNVItems, inactiveNVItems, okayNVItems, count, (long)Math.Round((double)((((float)position) / ((float)count)) * 100f)));
                                asyncOp.Post(this.onNVItemsStatusDelegate, args2);
                            }
                        }
                        finally
                        {
                            if (enumerator2 is IDisposable)
                            {
                                (enumerator2 as IDisposable).Dispose();
                            }
                        }
                        writer.Close();
                    }
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                exc = exception1;
                ProjectData.ClearProjectError();
            }
            this.CompletionMethod(exc, this.Cancelled(), asyncOp);
        }
        private void NVItemsReportStatus(object status)
        {
            NVItemsStatusEventArgs e = (NVItemsStatusEventArgs)status;

            this.OnNVItemsStatusChanged(e);
        }
Ejemplo n.º 4
0
        public void DoRestoreNVItems()
        {
            long         position    = 0L;
            long         totalLength = 0L;
            int          num         = 0;
            int          num2        = 0;
            int          num4        = 0;
            int          num5        = 0;
            StreamReader reader      = new StreamReader(this._writeNVItems.FileName);
            ArrayList    list        = new ArrayList();

            totalLength = reader.BaseStream.Length;
            while (reader.Peek() != -1)
            {
                string str = reader.ReadLine();
                if (str.Contains("Parameter bad"))
                {
                    num++;
                }
                else if (str.Contains("Access denied"))
                {
                    num2++;
                }
                else if (str.Contains("Inactive item"))
                {
                    num4++;
                }
                else if (str.Contains("OK"))
                {
                    num5++;
                }
                list.Add(str);
                position = reader.BaseStream.Position;
                NVItemsStatusEventArgs arg = new NVItemsStatusEventArgs(position, (long)num, (long)num2, (long)num4, (long)num5, totalLength, (long)Math.Round((double)((((float)position) / ((float)totalLength)) * 100f)));
                this._asyncOp.Post(this.onNVItemsStatusDelegate, arg);
            }
            reader.Close();
            this._writeNVItems.Dispose();
            if (Operators.ConditionalCompareObjectEqual(list[0], "[NV items]", false))
            {
                int num9 = list.Count - 1;
                for (int i = 3; i <= num9; i++)
                {
                    string left     = "";
                    string strInput = "";
                    string str2     = "";
                    int    num10    = Conversions.ToInteger(Operators.SubtractObject(NewLateBinding.LateGet(list[i], null, "IndexOf", new object[] { "(" }, null, null, null), 1));
                    for (int j = 0; j <= num10; j++)
                    {
                        left = Conversions.ToString(Operators.AddObject(left, NewLateBinding.LateIndexGet(list[i], new object[] { j }, null)));
                    }
                    if (list[i].ToString().Contains("OK"))
                    {
                        if (list[i + 1].ToString().Contains("|"))
                        {
                            str2     = list[i + 1].ToString();
                            strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]);
                            str2     = list[i + 2].ToString();
                            strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]);
                            str2     = list[i + 3].ToString();
                            strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]);
                            str2     = list[i + 4].ToString();
                            strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]);
                            str2     = list[i + 5].ToString();
                            strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]);
                            str2     = list[i + 6].ToString();
                            strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]);
                            str2     = list[i + 7].ToString();
                            strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]);
                            str2     = list[i + 8].ToString();
                            strInput = strInput + str2.Remove(str2.IndexOf("|")).TrimEnd(new char[0]);
                        }
                        else
                        {
                            strInput = (((strInput + list[i + 1].ToString() + list[i + 2].ToString()) + list[i + 3].ToString() + list[i + 4].ToString()) + list[i + 5].ToString() + list[i + 6].ToString()) + list[i + 7].ToString() + list[i + 8].ToString();
                        }
                        strInput = strInput.Replace(" ", "");
                        string strConsoleOut = "DIAG_NV_READ_F, RestoreNVItems - " + left.ToString();
                        EFS_Professional.Command inCommand = new EFS_Professional.Command(Qcdm.Cmd.DIAG_NV_WRITE_F, ConversionUtils.HexStringToBytes(strInput), strConsoleOut);
                        this._myQueue.Add(ref inCommand);
                    }
                    i++;
                }
            }
            else
            {
                Interaction.MsgBox("Invalid NV Items file!", MsgBoxStyle.Critical, "Error!");
                return;
            }
            this._asyncOp.Post(this.onPrepareForRestoreCompleted, new EventArgs());
            this._asyncOp.OperationCompleted();
        }