コード例 #1
0
ファイル: LookupService.cs プロジェクト: Generalcamo/OpenRA
 public DatabaseInfo getDatabaseInfo()
 {
     if (databaseInfo != null)
         return databaseInfo;
     try
     {
         // Synchronize since we're accessing the database file.
         lock (ioLock)
         {
             bool hasStructureInfo = false;
             byte [] delim = new byte[3];
             // Advance to part of file where database info is stored.
             file.Seek(-3,SeekOrigin.End);
             for (int i=0; i<STRUCTURE_INFO_MAX_SIZE; i++)
             {
                 file.Read(delim,0,3);
                 if (delim[0] == 255 && delim[1] == 255 && delim[2] == 255)
                 {
                     hasStructureInfo = true;
                     break;
                 }
                 file.Seek(-4,SeekOrigin.Current);
             }
             if (hasStructureInfo)
                 file.Seek(-6,SeekOrigin.Current);
             else
             {
                 // No structure info, must be pre Sep 2002 database, go back to end.
                 file.Seek(-3,SeekOrigin.End);
             }
             // Find the database info string.
             for (int i=0; i<DATABASE_INFO_MAX_SIZE; i++)
             {
                 file.Read(delim,0,3);
                 if (delim[0]==0 && delim[1]==0 && delim[2]==0)
                 {
                     byte[] dbInfo = new byte[i];
                     char[] dbInfo2 = new char[i];
                     file.Read(dbInfo,0,i);
                     for (int a0 = 0;a0 < i;a0++)
                         dbInfo2[a0] = Convert.ToChar(dbInfo[a0]);
                     // Create the database info object using the string.
                     this.databaseInfo = new DatabaseInfo(new String(dbInfo2));
                     return databaseInfo;
                 }
                 file.Seek(-4,SeekOrigin.Current);
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     return new DatabaseInfo("");
 }
コード例 #2
0
        public DatabaseInfo GetDatabaseInfo()
        {
            if (_databaseInfo != null)
            {
                return _databaseInfo;
            }
            try
            {
                // Synchronize since we're accessing the database file.
                lock (_ioLock)
                {
                    bool hasStructureInfo = false;

                    // Advance to part of file where database info is stored.
                    int position = FromEnd(-3);
                    for (int i = 0; i < DbFlags.STRUCTURE_INFO_MAX_SIZE; i++)
                    {
                        var delim = _dbReader.Read(position, 3);
                        position += 3;
                        if (delim[0] == 255 && delim[1] == 255 && delim[2] == 255)
                        {
                            hasStructureInfo = true;
                            break;
                        }
                        position += -4;
                    }
                    if (hasStructureInfo)
                    {
                        position += -6;
                    }
                    else
                    {
                        // No structure info, must be pre Sep 2002 database, go back to end.
                        position += -3;
                    }
                    // Find the database info string.
                    for (int i = 0; i < DbFlags.DATABASE_INFO_MAX_SIZE; i++)
                    {
                        var delim = _dbReader.Read(position, 3);
                        if (delim[0] == 0 && delim[1] == 0 && delim[2] == 0)
                        {
                            char[] dbInfo2 = new char[i];
                            var dbInfo = _dbReader.Read(position, i);
                            position += i;
                            for (int a0 = 0; a0 < i; a0++)
                            {
                                dbInfo2[a0] = Convert.ToChar(dbInfo[a0]);
                            }
                            // Create the database info object using the string.
                            _databaseInfo = new DatabaseInfo(new String(dbInfo2));
                            return _databaseInfo;
                        }
                        position += -1;
                    }
                }
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message);
            }
            return new DatabaseInfo("");
        }
コード例 #3
0
 public DatabaseInfo getDatabaseInfo()
 {
     if (databaseInfo != null)
     {
         return(databaseInfo);
     }
     try
     {
         // Synchronize since we're accessing the database file.
         lock (ioLock)
         {
             bool    hasStructureInfo = false;
             byte [] delim            = new byte[3];
             // Advance to part of file where database info is stored.
             file.Seek(-3, SeekOrigin.End);
             for (int i = 0; i < STRUCTURE_INFO_MAX_SIZE; i++)
             {
                 file.Read(delim, 0, 3);
                 if (delim[0] == 255 && delim[1] == 255 && delim[2] == 255)
                 {
                     hasStructureInfo = true;
                     break;
                 }
                 file.Seek(-4, SeekOrigin.Current);
             }
             if (hasStructureInfo)
             {
                 file.Seek(-6, SeekOrigin.Current);
             }
             else
             {
                 // No structure info, must be pre Sep 2002 database, go back to end.
                 file.Seek(-3, SeekOrigin.End);
             }
             // Find the database info string.
             for (int i = 0; i < DATABASE_INFO_MAX_SIZE; i++)
             {
                 file.Read(delim, 0, 3);
                 if (delim[0] == 0 && delim[1] == 0 && delim[2] == 0)
                 {
                     byte[] dbInfo  = new byte[i];
                     char[] dbInfo2 = new char[i];
                     file.Read(dbInfo, 0, i);
                     for (int a0 = 0; a0 < i; a0++)
                     {
                         dbInfo2[a0] = Convert.ToChar(dbInfo[a0]);
                     }
                     // Create the database info object using the string.
                     this.databaseInfo = new DatabaseInfo(new String(dbInfo2));
                     return(databaseInfo);
                 }
                 file.Seek(-4, SeekOrigin.Current);
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     return(new DatabaseInfo(""));
 }