Exemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string text       = string.Empty;
            string partToDisp = string.Empty;

            if (!Directory.Exists(this.AppPath + @"\DF"))
            {
                Directory.CreateDirectory(this.AppPath + @"\DF");
            }
            if (string.IsNullOrEmpty(this.txtFileName.Text))
            {
                Interaction.MsgBox("Please enter a valid file name!", MsgBoxStyle.Exclamation, null);
            }
            else if (string.IsNullOrEmpty(this.txtDisplayName.Text))
            {
                Interaction.MsgBox("Please enter a valid display name!", MsgBoxStyle.Exclamation, null);
            }
            else if (string.IsNullOrEmpty(this.txtDescription.Text))
            {
                Interaction.MsgBox("Please enter a brief description of the Device Filter!", MsgBoxStyle.Exclamation, null);
            }
            else
            {
                if (this.txtFileName.Text.ToLower().EndsWith(".bin"))
                {
                    text = this.txtFileName.Text;
                }
                else
                {
                    text = this.txtFileName.Text + ".bin";
                }
                int num2 = this.lbPartToDisp.Items.Count - 1;
                for (int i = 0; i <= num2; i++)
                {
                    partToDisp = partToDisp + this.lbPartToDisp.Items[i].ToString() + "|";
                }
                partToDisp = partToDisp.TrimEnd(new char[] { '|' });
                DeviceFilterClass devFilter = new DeviceFilterClass(this.AppPath + @"\DF\" + text, this.txtDisplayName.Text, partToDisp, this.txtDescription.Text);
                try
                {
                    if (DeviceFilterClass.WriteBIN(devFilter, this.AppPath + @"\DF\" + text))
                    {
                        Interaction.MsgBox("Device Filter was written successfully!", MsgBoxStyle.Information, null);
                        this.Close();
                    }
                    else
                    {
                        Interaction.MsgBox("An error occurred while writing the file.", MsgBoxStyle.Critical, null);
                        this.Close();
                    }
                }
                catch (Exception exception1)
                {
                    ProjectData.SetProjectError(exception1);
                    Exception exception = exception1;
                    Interaction.MsgBox(exception.Message, MsgBoxStyle.Critical, null);
                    ProjectData.ClearProjectError();
                }
            }
        }
Exemplo n.º 2
0
        public static bool WriteBIN(DeviceFilterClass devFilter, string fileName)
        {
            bool flag;

            try
            {
                using (FileStream stream = File.Create(fileName))
                {
                    binWriter = new BinaryWriter(stream);
                    binWriter.Write(0x17042013);
                    binWriter.Write(ConversionUtils.BytesToHexString(Encoding.UTF8.GetBytes(devFilter._displayName)));
                    binWriter.Write(ConversionUtils.BytesToHexString(Encoding.UTF8.GetBytes(devFilter._partToDisp)));
                    binWriter.Write(ConversionUtils.BytesToHexString(Encoding.UTF8.GetBytes(devFilter._description)));
                    binWriter.Write(0x30091989);
                    binWriter.Close();
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                Interaction.MsgBox("Error writing binary file!", MsgBoxStyle.Critical, null);
                flag = false;
                ProjectData.ClearProjectError();
            }
            return(flag);
        }
Exemplo n.º 3
0
        public static bool ReadBIN(string fileName, ref DeviceFilterClass devFilter)
        {
            bool flag;

            try
            {
                string str;
                string str2;
                string str3;
                using (FileStream stream = File.OpenRead(fileName))
                {
                    binReader = new BinaryReader(stream);
                    if (binReader.ReadInt32() != 0x17042013)
                    {
                        Interaction.MsgBox("Device Filter contains an invalid header!", MsgBoxStyle.Critical, null);
                        return(false);
                    }
                    str2 = Encoding.UTF8.GetString(ConversionUtils.HexStringToBytes(binReader.ReadString()));
                    str3 = Encoding.UTF8.GetString(ConversionUtils.HexStringToBytes(binReader.ReadString()));
                    str  = Encoding.UTF8.GetString(ConversionUtils.HexStringToBytes(binReader.ReadString()));
                    binReader.BaseStream.Position = binReader.BaseStream.Length - 4L;
                    if (binReader.ReadInt32() != 0x30091989)
                    {
                        Interaction.MsgBox("Device Filter contains an invalid signature!", MsgBoxStyle.Critical, null);
                        return(false);
                    }
                    binReader.Close();
                }
                devFilter = new DeviceFilterClass(fileName, str2, str3, str);
                flag      = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                Interaction.MsgBox("Error reading binary file!", MsgBoxStyle.Critical, null);
                flag = false;
                ProjectData.ClearProjectError();
            }
            return(flag);
        }
Exemplo n.º 4
0
        private void LoadFile(string fileName)
        {
            DeviceFilterClass devFilter = null;

            string[] strArray = new string[0];
            if (DeviceFilterClass.ReadBIN(fileName, ref devFilter))
            {
                this.txtDisplayName.Text = devFilter.DisplayName;
                this.lbPartToDisp.Items.Clear();
                foreach (string str in Strings.Split(devFilter.PartitionsToDisplay, "|", -1, CompareMethod.Binary))
                {
                    if (!string.IsNullOrEmpty(str))
                    {
                        this.lbPartToDisp.Items.Add(str);
                    }
                }
                this.txtDescription.Text = devFilter.Description;
            }
            else
            {
                Interaction.MsgBox("Unable to read Device Filter!", MsgBoxStyle.Critical, null);
                this.Close();
            }
        }