+ // File in which the database contents is stored. This is null
+ // when DBStatus is NOT_READY.
+ internal FileInfo FileInfo;
+ // When the database file is loaded last.
+ internal DateTime LastLoaded = DateTime.Now;
+
+ public enum LoadStatus
+ {
+ None,
+ InvalidLoadMethod,
+ NotAvailable,
+ NotReadable,
+ InvalidContents,
+ };
+
+ public LoadStatus LastLoadStatus = LoadStatus.None;
+
+ static MDatabase ()
+ {
+ string share_dir = (Environment.GetFolderPath
+ (Environment.SpecialFolder.CommonApplicationData));
+ string usr_dir = (Environment.GetFolderPath
+ (Environment.SpecialFolder.ApplicationData));
+
+ try {
+ string dir = Environment.GetEnvironmentVariable ("M17NDIR");
+ DBDirs[1] = new MDatabaseDir (dir);
+ } catch {
+ try {
+ DBDirs[1] = new MDatabaseDir (Path.Combine (usr_dir, ".m17n.d"));
+ } catch (ArgumentException) {
+ DBDirs[1] = new MDatabaseDir (Path.Combine (usr_dir, "_m17n_d"));
+ }
+ }
+ DBDirs[2] = new MDatabaseDir (null);
+ DBDirs[3] = new MDatabaseDir (Path.Combine (share_dir, "m17n"));
+ update_all (true);
+ }
+
+ public static string ApplicationDir
+ {
+ get { return (DBDirs[1].Dirname); }
+ set { DBDirs[2] = new MDatabaseDir (value); update_all (true); }
+ }
+
+ // Update all listing and directories. Return true iff some are
+ // really updated.
+ private static bool update_all (bool force)
+ {
+ if (! force && DateTime.Now - LastUpdateTime < CheckInterval)
+ return false;
+
+ bool updated = false;
+ for (int i = 1; i < 4; i++)
+ if (DBDirs[i].Dirname != null)
+ {
+ DBDirs[i].Refresh ();
+ if (LastUpdateTime < DBDirs[i].ListChangeTime)
+ {
+ update_list (i);
+ updated = true;
+ }
+ if (LastUpdateTime < DBDirs[i].DirChangeTime)
+ {
+ update_dir (i);
+ updated = true;
+ }
+ }
+ if (updated)
+ LastUpdateTime = DateTime.Now;
+ return updated;
+ }
+
+ public static void Dump ()
+ {
+ update_all (false);
+ Console.WriteLine ("[DBDirs]");
+ for (int i = 1; i < 4; i++)
+ if (DBDirs[i].Dirname != null)
+ {
+ if (DBDirs[i].DirInfo != null)
+ {
+ Console.Write ("{0}:{1}", i, DBDirs[i].DirInfo.FullName);
+ if (DBDirs[i].ListInfo != null)
+ Console.WriteLine (" {0}", DBDirs[i].ListInfo);
+ else
+ Console.WriteLine (" .. no mdb.dir");
+ }
+ else
+ Console.WriteLine ("{0}:{1} .. not exist", i, DBDirs[i].Dirname);
+ }