예제 #1
0
        //from SetUp
        public void SetDefualtFile(DBFileInfo fileInfo)
        {
            foreach (string filePath in dbInfoDictionary.Keys)
            {
                dbInfoDictionary[filePath].isDefault = false;
            }

            if (dbInfoDictionary.ContainsKey(fileInfo.FilePath))
            {
                dbInfoDictionary.Remove(fileInfo.FilePath);
            }
            dbInfoDictionary.Add(fileInfo.FilePath, fileInfo);
        }
예제 #2
0
        public void WriteINI()
        {
            try
            {
                if (File.Exists(iniPath))
                {
                    FileStream fs = File.Open(iniPath, FileMode.Create);

                    using (StreamWriter sw = new StreamWriter(fs))
                    {
                        string sp = "##";

                        foreach (string filePath in dbInfoDictionary.Keys)
                        {
                            DBFileInfo dbfile = dbInfoDictionary[filePath];
                            if (dbfile.isDefault)
                            {
                                sw.WriteLine(dbfile.DateModified + sp + dbfile.ModifiedBy + sp + dbfile.FilePath + sp + dbfile.Comments);
                                break;
                            }
                        }

                        foreach (string filePath in dbInfoDictionary.Keys)
                        {
                            DBFileInfo dbfile = dbInfoDictionary[filePath];
                            if (dbfile.isDefault)
                            {
                                continue;
                            }
                            if (File.Exists(filePath))
                            {
                                sw.WriteLine(dbfile.DateModified + sp + dbfile.ModifiedBy + sp + dbfile.FilePath + sp + dbfile.Comments);
                            }
                            else
                            {
                                sw.WriteLine("Not Exist: " + filePath);
                            }
                        }
                        sw.Close();
                    }
                    fs.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to write ini file: \n" + ex.Message);
            }
        }
예제 #3
0
        private void ReadINI()
        {
            try
            {
                if (File.Exists(iniPath))
                {
                    using (StreamReader sr = new StreamReader(iniPath))
                    {
                        bool   firstLine = true;
                        string line;
                        while ((line = sr.ReadLine()) != null)
                        {
                            DBFileInfo dbFileInfo = new DBFileInfo();
                            dbFileInfo.isDefault = firstLine;

                            string[] strFileInfo = line.Split(splitter, StringSplitOptions.None);
                            if (strFileInfo.Length == 4)
                            {
                                dbFileInfo.DateModified = strFileInfo[0];
                                dbFileInfo.ModifiedBy   = strFileInfo[1];
                                dbFileInfo.FilePath     = strFileInfo[2];
                                dbFileInfo.Comments     = strFileInfo[3];
                                if (File.Exists(dbFileInfo.FilePath))
                                {
                                    dbFileInfo.FileName = Path.GetFileName(dbFileInfo.FilePath);
                                }

                                if (!dbInfoDictionary.ContainsKey(dbFileInfo.FilePath))
                                {
                                    dbInfoDictionary.Add(dbFileInfo.FilePath, dbFileInfo);
                                }
                                firstLine = false;
                            }
                        }
                        sr.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to read ini file: \n" + ex.Message);
            }
        }
예제 #4
0
 private void SearchDefaultFile()
 {
     if (dbInfoDictionary.Count > 0)
     {
         foreach (string filePath in dbInfoDictionary.Keys)
         {
             DBFileInfo dbFileInfo = dbInfoDictionary[filePath];
             if (dbFileInfo.isDefault)
             {
                 if (File.Exists(dbFileInfo.FilePath))
                 {
                     dbExist       = true;
                     DefaultDBFile = dbFileInfo.FilePath;
                 }
                 break;
             }
         }
     }
 }