| 1 | 
   | 
 unit ConnectionManager; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 2 | 
   | 
 interface | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 3 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 | 4 | 
 < | 
 uses TypeDefs, DataAccess, Access_OniArchive, Access_OUP_ADB; | 
 
 
 
 
 
 
 
 
 
 | 4 | 
 > | 
 uses TypeDefs, DataAccess, Access_OniArchive, Access_OUP_ADB, Access_OniSplitArchive; | 
 
 
 
 
 
 
 
 
 
 
 
 | 5 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 6 | 
   | 
 type | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 7 | 
   | 
   TConnections = array of TDataAccess; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 17 | 
   | 
     function GetConnectionCount: Integer; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 18 | 
   | 
     function GetConnection(ConnectionID: Integer): TDataAccess; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 19 | 
   | 
     function GetConnectionByIndex(Index: Integer): TDataAccess; | 
 
 
 
 
 
 
 
 
 | 20 | 
 + | 
     function GetConnectionIndex(ConnectionID: Integer): Integer; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 21 | 
   | 
     procedure RemoveConnection(ArrayIndex: Integer); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 22 | 
   | 
   protected | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 23 | 
   | 
   public | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 24 | 
   | 
     property Count: Integer read GetConnectionCount; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 25 | 
   | 
     property Connection[ConnectionID: Integer]: TDataAccess read GetConnection; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 26 | 
   | 
     property ConnectionByIndex[Index: Integer]: TDataAccess read GetConnectionByIndex; | 
 
 
 
 
 
 
 
 
 | 27 | 
 + | 
     property ConnectionIndexByID[ConnectionID: Integer]: Integer read GetConnectionIndex; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 28 | 
   | 
     property OnCoonnectionListChanged: TConnectionListChangedEvent read FConnectionListChanged write FConnectionListChanged; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 29 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 30 | 
   | 
     constructor Create; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 34 | 
   | 
     function CloseConnectionByIndex(Index: Integer; var Msg: TStatusMessages): Boolean; overload; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 35 | 
   | 
     function CloseConnection(ID: Integer; var Msg: TStatusMessages): Boolean; overload; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 36 | 
   | 
     function CloseConnection(FileName: String; var Msg: TStatusMessages): Boolean; overload; | 
 
 
 
 
 
 
 
 
 | 37 | 
 + | 
     function FileOpened(FileName: String): Integer; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 38 | 
   | 
   published | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 39 | 
   | 
   end; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 40 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 41 | 
   | 
  | 
 
 
 
 
 
 
 
 
 | 42 | 
 + | 
 var | 
 
 
 
 
 
 
 
 
 | 43 | 
 + | 
   ConManager: TConnectionManager; | 
 
 
 
 
 
 
 
 
 | 44 | 
 + | 
  | 
 
 
 
 
 
 
 
 
 | 45 | 
 + | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 46 | 
   | 
 implementation | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 47 | 
   | 
 uses | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 48 | 
   | 
   SysUtils, Dialogs; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 57 | 
   | 
   Result := Length(FConnections); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 58 | 
   | 
 end; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 59 | 
   | 
  | 
 
 
 
 
 
 
 
 
 | 60 | 
 + | 
 function TConnectionManager.GetConnectionIndex(ConnectionID: Integer): Integer; | 
 
 
 
 
 
 
 
 
 | 61 | 
 + | 
 var | 
 
 
 
 
 
 
 
 
 | 62 | 
 + | 
   i: Integer; | 
 
 
 
 
 
 
 
 
 | 63 | 
 + | 
 begin | 
 
 
 
 
 
 
 
 
 | 64 | 
 + | 
   Result := -1; | 
 
 
 
 
 
 
 
 
 | 65 | 
 + | 
   if Count > 0 then | 
 
 
 
 
 
 
 
 
 | 66 | 
 + | 
     for i := 0 to Count - 1 do | 
 
 
 
 
 
 
 
 
 | 67 | 
 + | 
       if ConnectionByIndex[i].ConnectionID = ConnectionID then | 
 
 
 
 
 
 
 
 
 | 68 | 
 + | 
       begin | 
 
 
 
 
 
 
 
 
 | 69 | 
 + | 
         Result := i; | 
 
 
 
 
 
 
 
 
 | 70 | 
 + | 
         Break; | 
 
 
 
 
 
 
 
 
 | 71 | 
 + | 
       end; | 
 
 
 
 
 
 
 
 
 | 72 | 
 + | 
 end; | 
 
 
 
 
 
 
 
 
 | 73 | 
 + | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 74 | 
   | 
 function TConnectionManager.GetConnection(ConnectionID: Integer): TDataAccess; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 75 | 
   | 
 var | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 76 | 
   | 
   i: Integer; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 150 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 151 | 
   | 
   ext := UpperCase(ExtractFileExt(FileName)); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 152 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 | 153 | 
 < | 
   if ext = 'ODB' then | 
 
 
 
 
 
 
 
 
 
 | 153 | 
 > | 
   if ext = '.OLDB' then | 
 
 
 
 
 
 
 
 
 
 
 
 | 154 | 
   | 
     backend := DB_ADB | 
 
 
 
 
 
 
 
 
 
 
 
 | 155 | 
 < | 
   else if ext = 'DAT' then | 
 
 
 
 
 
 
 
 
 
 | 155 | 
 > | 
   else if ext = '.DAT' then | 
 
 
 
 
 
 
 
 
 
 
 
 | 156 | 
   | 
     backend := DB_ONI | 
 
 
 
 
 
 
 
 
 | 157 | 
 + | 
   else if ext = '.ONI' then | 
 
 
 
 
 
 
 
 
 | 158 | 
 + | 
     backend := DB_ONISPLIT | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 159 | 
   | 
   else | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 160 | 
   | 
   begin | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 161 | 
   | 
     Msg := SM_UnknownExtension; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 169 | 
   | 
       FConnections[i] := TAccess_OniArchive.Create(FileName, FLastID + 1, CreateMsg); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 170 | 
   | 
     DB_ADB: | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 171 | 
   | 
       FConnections[i] := TAccess_OUP_ADB.Create(FileName, FLastID + 1, CreateMsg); | 
 
 
 
 
 
 
 
 
 | 172 | 
 + | 
     DB_ONISPLIT: | 
 
 
 
 
 
 
 
 
 | 173 | 
 + | 
       FConnections[i] := TAccess_OniSplitArchive.Create(FileName, FLastID + 1, CreateMsg); | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 174 | 
   | 
   end; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 175 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 176 | 
   | 
   if CreateMsg = SM_OK then | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 177 | 
   | 
   begin | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 178 | 
   | 
     FLastID := FConnections[i].ConnectionID; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 179 | 
   | 
     Result := FLastID; | 
 
 
 
 
 
 
 
 
 | 180 | 
 + | 
     Msg := SM_OK; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 181 | 
   | 
   end | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 182 | 
   | 
   else | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 183 | 
   | 
   begin | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 184 | 
   | 
     FConnections[i].Close; | 
 
 
 
 
 
 
 
 
 
 | 159 | 
 – | 
     FConnections[i].Free; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 185 | 
   | 
     FConnections[i] := nil; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 186 | 
   | 
     SetLength(FConnections, Length(FConnections) - 1); | 
 
 
 
 
 
 
 
 
 
 
 
 | 187 | 
 < | 
     Msg := SM_UnknownError; | 
 
 
 
 
 
 
 
 
 
 | 187 | 
 > | 
     Msg := CreateMsg; | 
 
 
 
 
 
 
 
 
 
 
 
 | 188 | 
   | 
   end; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 189 | 
   | 
 end; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 190 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 264 | 
   | 
 end; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 265 | 
   | 
  | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 266 | 
   | 
  | 
 
 
 
 
 
 
 
 
 | 267 | 
 + | 
 function TConnectionManager.FileOpened(FileName: String): Integer; | 
 
 
 
 
 
 
 
 
 | 268 | 
 + | 
 var | 
 
 
 
 
 
 
 
 
 | 269 | 
 + | 
   i: Integer; | 
 
 
 
 
 
 
 
 
 | 270 | 
 + | 
 begin | 
 
 
 
 
 
 
 
 
 | 271 | 
 + | 
   Result := -1; | 
 
 
 
 
 
 
 
 
 | 272 | 
 + | 
   if Length(FConnections) > 0 then | 
 
 
 
 
 
 
 
 
 | 273 | 
 + | 
     for i := 0 to High(FConnections) do | 
 
 
 
 
 
 
 
 
 | 274 | 
 + | 
       if FConnections[i].FileName = FileName then | 
 
 
 
 
 
 
 
 
 | 275 | 
 + | 
       begin | 
 
 
 
 
 
 
 
 
 | 276 | 
 + | 
         Result := FConnections[i].ConnectionID; | 
 
 
 
 
 
 
 
 
 | 277 | 
 + | 
         Exit; | 
 
 
 
 
 
 
 
 
 | 278 | 
 + | 
       end; | 
 
 
 
 
 
 
 
 
 | 279 | 
 + | 
 end; | 
 
 
 
 
 
 
 
 
 | 280 | 
 + | 
  | 
 
 
 
 
 
 
 
 
 | 281 | 
 + | 
  | 
 
 
 
 
 
 
 
 
 | 282 | 
 + | 
 initialization | 
 
 
 
 
 
 
 
 
 | 283 | 
 + | 
   ConManager := TConnectionManager.Create; | 
 
 
 
 
 
 
 
 
 | 284 | 
 + | 
 finalization | 
 
 
 
 
 
 
 
 
 | 285 | 
 + | 
   ConManager.Free; | 
 
 
 
 
 
 
 
 
 
 
 
 
 
 | 286 | 
   | 
 end. |