From e32c994e2304fe1cf7412bb0874f5c3de9f26d8f Mon Sep 17 00:00:00 2001 From: handa Date: Mon, 8 Jun 2009 13:58:53 +0000 Subject: [PATCH] *** empty log message *** --- MDatabase.cs | 103 +++++++++++++++++++++++++++++++++------------------------- database.cs | 5 +-- 2 files changed, 60 insertions(+), 48 deletions(-) diff --git a/MDatabase.cs b/MDatabase.cs index a532b96..e8ca8e5 100644 --- a/MDatabase.cs +++ b/MDatabase.cs @@ -514,7 +514,6 @@ namespace M17N.Core for (int i = 0; i < mdbs.Count; i++) if (mdbs[i].ListIndex == mdb.ListIndex) { - mdbs[i].DBStatus = MDBStatus.INVALID; mdbs[i] = mdb; return; @@ -532,22 +531,37 @@ namespace M17N.Core private static void register (int list_idx, int dir_idx, Tag tag, MDatabaseInfo info) { + Dictionary> dict + = tag.HasWildcard ? wdict : ndict; List mdbs; MDatabase mdb; - if (ndict.TryGetValue (tag, out mdbs)) + if (dict.TryGetValue (tag, out mdbs)) for (int i = 0; i < mdbs.Count; i++) { mdb = mdbs[i]; - if (mdb.ListIndex == list_idx) + if (mdb.ListIndex == list_idx && mdb.DirIndex >= dir_idx) { if (mdb.DBStatus == MDBStatus.INVALID) M17n.DebugPrint ("registering: {0}\n", mdb); else M17n.DebugPrint ("updating: {0}\n", mdb); - mdb.DBType = dir_idx == -1 ? MDBType.AUTO : MDBType.MULTIPLE; - mdb.DBStatus = MDBStatus.NOT_READY; mdb.DirIndex = dir_idx; + if (dict == wdict) + { + mdb.DBType = MDBType.WILDCARD; + mdb.DBStatus = MDBStatus.NOT_READY; + } + else if (dir_idx == -1) + { + mdb.DBType = MDBType.AUTO; + mdb.DBStatus = MDBStatus.NOT_READY; + } + else + { + mdb.DBType = MDBType.MULTIPLE; + mdb.DBStatus = MDBStatus.READY; + } mdb.Info = info; return; } @@ -555,7 +569,7 @@ namespace M17N.Core else { mdbs = new List (1); - ndict.Add (tag, mdbs); + dict.Add (tag, mdbs); } mdb = new MDatabase (list_idx, dir_idx, tag, info); M17n.DebugPrint ("registering: {0}\n", mdb); @@ -581,7 +595,10 @@ namespace M17N.Core if (Path.IsPathRooted (filename)) { DirIndex = 0; - DBStatus = MDBStatus.READY; + if (File.Exists (filename)) + DBStatus = MDBStatus.READY; + else + DBStatus = MDBStatus.INVALID; } else { @@ -622,6 +639,7 @@ namespace M17N.Core // DBDirs[list_idx]. private static void update_list (int list_idx) { + M17n.DebugPrint ("Updating list: {0}\n", list_idx); // At first disable all target databases. foreach (KeyValuePair> kv in wdict) foreach (MDatabase mdb in kv.Value) @@ -673,6 +691,7 @@ namespace M17N.Core // Update (or disable) databases in DBDirs[dir_idx]. private static void update_dir (int dir_idx) { + M17n.DebugPrint ("Updating dir: {0}\n", dir_idx); // Reset all databases in DBDirs[dir_idx]. foreach (KeyValuePair> kv in ndict) foreach (MDatabase mdb in kv.Value) @@ -742,49 +761,45 @@ namespace M17N.Core private static void maybe_expand_wildcard (Tag tag) { foreach (KeyValuePair> kv in wdict) - if (kv.Key.Match (tag)) - foreach (MDatabase mdb in kv.Value) - if (mdb.DBStatus == MDBStatus.NOT_READY) - mdb.expand_wildcard (); - } - - private bool update_status () - { - if (DBType == MDBType.UNKNOWN) - return true; - if (DBStatus == MDBStatus.READY - && FileInfo != null) { - FileInfo.Refresh (); - if (CheckedTime >= FileInfo.LastWriteTime) - return true; - - + M17n.DebugPrint ("expand check: {0}\n", kv.Key); + if (kv.Key.Match (tag)) { - FileInfo[] files - = DBDirs[DirIndex].DirInfo.GetFiles (Info.Filename); - if (files.Count > 0) - FileInfo = files[0]; + foreach (MDatabase mdb in kv.Value) + { + if (mdb.DBStatus == MDBStatus.NOT_READY) + mdb.expand_wildcard (); + } } - } - - if (DBDirs[DirIndex].DirInfo == null) - return false; - FileInfo[] files = DBDirs[DirIndex].DirInfo.GetFiles (Info.Filename); - if (files.Length == 0) - return false; - FileInfo = files[0]; - return true; } - private bool find_file () + private bool update_status () { - if (DirIndex == 0) + if (DBType == MDBType.UNKNOWN) + return true; + if (DBStatus == MDBStatus.INVALID) + return false; + if (DBStatus == MDBStatus.READY) { - + if (DirIndex > 0 + || File.Exists (FileInfo.FullName)) + return true; + DBStatus = MDBStatus.INVALID; + return false; } - return true; + for (int i = 1; i < 4; i++) + if (DBDirs[i] != null) + { + string filename = Path.Combine (DBDirs[i].Dirname, Info.Filename); + if (File.Exists (filename)) + { + FileInfo = new FileInfo (filename); + DirIndex = i; + return true; + } + } + return false; } public static MDatabase Find (Tag tag) @@ -813,7 +828,7 @@ namespace M17N.Core if (! ndict.TryGetValue (tag, out mdbs)) return null; for (int i = 0; i < mdbs.Count; i++) - if ((mdb = mdbs[i]).check_file ()) + if ((mdb = mdbs[i]).update_status ()) return mdb; return null; } @@ -830,7 +845,7 @@ namespace M17N.Core foreach (KeyValuePair> kv in ndict) if (kv.Key.Match (tag)) foreach (MDatabase mdb in kv.Value) - if (mdb.check_file ()) + if (mdb.update_status ()) { list.Add (mdb); break; @@ -841,7 +856,7 @@ namespace M17N.Core List mdbs; if (ndict.TryGetValue (tag, out mdbs)) foreach (MDatabase mdb in mdbs) - if (mdb.check_file ()) + if (mdb.update_status ()) { list.Add (mdb); break; diff --git a/database.cs b/database.cs index ce44154..a2ad183 100644 --- a/database.cs +++ b/database.cs @@ -13,7 +13,6 @@ public class Test MDatabase.Tag tag = new MDatabase.Tag (MSymbol.Of ("input-method"), MSymbol.t, MSymbol.Of ("unicode")); - DirectoryInfo dirinfo = new DirectoryInfo ("/home/handa/.m17n.d"); while (true) { @@ -21,9 +20,7 @@ public class Test string str = Console.ReadLine (); if (str == null || str == "quit" || str == "exit") break; - dirinfo.Refresh (); - Console.WriteLine (dirinfo.LastWriteTimeUtc - + ":" + MDatabase.Find (tag)); + Console.WriteLine (MDatabase.Find (tag)); } } } -- 1.7.10.4