Exemple #1
0
        public void SaveRecord()
        {
            FileStream   fs = null;
            StreamWriter sw = null;

            try
            {
                fs = File.Open(_recordFileName, FileMode.Create, FileAccess.Write, FileShare.Read);
                sw = new StreamWriter(fs);
                foreach (byte b in _record)
                {
                    MK52_Button btn = m_Buttons[(int)b - 1];
                    sw.WriteLine(btn.Moniker);
                }
            }
            catch (Exception ex)
            {
                throw new FileNotFoundException(ex.Message);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }
Exemple #2
0
        public void LoadRecord(string filename)
        {
            _recordFileName = filename;
            FileStream   fs = null;
            StreamReader sr = null;

            try
            {
                fs = File.Open(_recordFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                sr = new StreamReader(fs);
                _record.Clear();
                while (!sr.EndOfStream)
                {
                    string      buttonName = sr.ReadLine();
                    MK52_Button iB         = m_Buttons.Find(
                        delegate(MK52_Button x) { return(x.Moniker == buttonName); });
                    _record.Add((byte)iB.Scancode);
                }
            }
            catch (Exception ex)
            {
                throw new FileNotFoundException(ex.Message);
            }
            finally
            {
                if (sr != null)
                {
                    sr.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
        }