for (int i = 0; i < mdbs.Count; i++)
if (mdbs[i].ListIndex == mdb.ListIndex)
{
-
mdbs[i].DBStatus = MDBStatus.INVALID;
mdbs[i] = mdb;
return;
private static void register (int list_idx, int dir_idx,
Tag tag, MDatabaseInfo info)
{
+ Dictionary<MDatabase.Tag, List<MDatabase>> dict
+ = tag.HasWildcard ? wdict : ndict;
List<MDatabase> 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;
}
else
{
mdbs = new List<MDatabase> (1);
- ndict.Add (tag, mdbs);
+ dict.Add (tag, mdbs);
}
mdb = new MDatabase (list_idx, dir_idx, tag, info);
M17n.DebugPrint ("registering: {0}\n", mdb);
if (Path.IsPathRooted (filename))
{
DirIndex = 0;
- DBStatus = MDBStatus.READY;
+ if (File.Exists (filename))
+ DBStatus = MDBStatus.READY;
+ else
+ DBStatus = MDBStatus.INVALID;
}
else
{
// 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<Tag, List<MDatabase>> kv in wdict)
foreach (MDatabase mdb in kv.Value)
// 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<Tag, List<MDatabase>> kv in ndict)
foreach (MDatabase mdb in kv.Value)
private static void maybe_expand_wildcard (Tag tag)
{
foreach (KeyValuePair<Tag, List<MDatabase>> 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)
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;
}
foreach (KeyValuePair<Tag, List<MDatabase>> 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;
List<MDatabase> mdbs;
if (ndict.TryGetValue (tag, out mdbs))
foreach (MDatabase mdb in mdbs)
- if (mdb.check_file ())
+ if (mdb.update_status ())
{
list.Add (mdb);
break;