Changeset 105 for trunk/Packages/ModularSystem/UModularSystem.pas
- Timestamp:
- Oct 9, 2012, 1:58:45 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/ModularSystem/UModularSystem.pas
r94 r105 6 6 7 7 uses 8 Classes, SysUtils, Contnrs ;8 Classes, SysUtils, Contnrs, URegistry; 9 9 10 10 type … … 19 19 TModule = class(TComponent) 20 20 private 21 FEnabled: Boolean; 21 22 FRunning: Boolean; 22 23 FInstalled: Boolean; 23 Manager: TModuleManager;24 FManager: TModuleManager; 24 25 FVersion: string; 25 26 FIdentification: string; … … 29 30 FDependencies: TStringList; 30 31 FDescription: TStringList; 32 procedure SetEnabled(AValue: Boolean); 31 33 procedure SetInstalled(AValue: Boolean); 32 34 procedure SetRunning(AValue: Boolean); 35 protected 36 procedure BeforeStart; virtual; 37 procedure AfterStart; virtual; 38 procedure BeforeStop; virtual; 39 procedure AfterStop; virtual; 33 40 public 34 41 API: TAPI; 35 MarkForInstall: Boolean;36 42 procedure Start; virtual; 37 43 procedure Stop; virtual; … … 48 54 property Running: Boolean read FRunning write SetRunning; 49 55 property Installed: Boolean read FInstalled write SetInstalled; 56 property Enabled: Boolean read FEnabled write SetEnabled; 50 57 published 58 property Manager: TModuleManager read FManager; 51 59 property Version: string read FVersion write FVersion; 52 60 property Identification: string read FIdentification write FIdentification; … … 79 87 procedure EnumModulesInstall(Dependencies, ModuleList: TStringList); 80 88 procedure EnumModulesUninstall(ModuleName: string; ModuleList: TStringList); 81 procedure RegisterModule(Module: TModule; MarkForInstall: Boolean = False);89 procedure RegisterModule(Module: TModule; Enabled: Boolean = True); 82 90 procedure UnregisterModule(Module: TModule); 83 91 procedure StartInstalled; 84 procedure Install Marked;92 procedure InstallEnabled; 85 93 procedure StopAll; 86 94 procedure UninstallAll; 95 procedure LoadFromRegistry(Context: TRegistryContext); 96 procedure SaveToRegistry(Context: TRegistryContext); 87 97 constructor Create(AOwner: TComponent); override; 88 98 destructor Destroy; override; … … 143 153 for I := 0 to Dependencies.Count - 1 do begin 144 154 Module := FindModuleByName(Dependencies[I]); 145 if Assigned(Module) then begin155 if Assigned(Module) and Module.Enabled then begin 146 156 if not Module.Running then Module.Start; 147 157 end else raise Exception.CreateFmt(SModuleNotFound, [ModuleName, Dependencies[I]]); … … 199 209 for I := 0 to Dependencies.Count - 1 do begin 200 210 Module := FindModuleByName(Dependencies[I]); 201 if Assigned(Module) then begin211 if Assigned(Module) and Module.Enabled then begin 202 212 if not Module.Installed then Module.Install; 203 213 end else raise Exception.CreateFmt(SModuleNotFound, [ModuleName, Dependencies[I]]); … … 248 258 249 259 procedure TModuleManager.RegisterModule(Module: TModule; 250 MarkForInstall: Boolean = False);260 Enabled: Boolean = True); 251 261 begin 252 262 Modules.Add(Module); 253 Module. Manager := Self;263 Module.FManager := Self; 254 264 Module.API := API; 255 Module. MarkForInstall := MarkForInstall;265 Module.Enabled := Enabled; 256 266 end; 257 267 … … 270 280 end; 271 281 272 procedure TModuleManager.Install Marked;282 procedure TModuleManager.InstallEnabled; 273 283 var 274 284 I: Integer; … … 276 286 for I := 0 to Modules.Count - 1 do 277 287 with TModule(Modules[I]) do 278 if not Installed and MarkForInstallthen Install;288 if not Installed and Enabled then Install; 279 289 end; 280 290 … … 301 311 inherited; 302 312 Modules := TObjectList.Create; 313 //Modules.OwnsObjects := False; 303 314 end; 304 315 … … 307 318 StopAll; 308 319 FreeAndNil(Modules); 309 inherited Destroy; 320 inherited; 321 end; 322 323 procedure TModuleManager.LoadFromRegistry(Context: TRegistryContext); 324 var 325 I: Integer; 326 begin 327 with TRegistryEx.Create do 328 try 329 RootKey := Context.RootKey; 330 for I := 0 to Modules.Count - 1 do 331 with TModule(Modules[I]) do begin 332 OpenKey(Context.Key + '\' + Identification, True); 333 Running := ReadBoolWithDefault('Run', Enabled); 334 end; 335 finally 336 Free; 337 end; 338 end; 339 340 procedure TModuleManager.SaveToRegistry(Context: TRegistryContext); 341 var 342 I: Integer; 343 begin 344 with TRegistryEx.Create do 345 try 346 RootKey := Context.RootKey; 347 for I := 0 to Modules.Count - 1 do 348 with TModule(Modules[I]) do begin 349 OpenKey(Context.Key + '\' + Identification, True); 350 WriteBool('Run', Running); 351 end; 352 finally 353 Free; 354 end; 310 355 end; 311 356 … … 318 363 end; 319 364 365 procedure TModule.BeforeStart; 366 begin 367 if Running then Exit; 368 if not Installed then Install; 369 Manager.StartDependencies(Identification, Dependencies); 370 end; 371 372 procedure TModule.AfterStart; 373 begin 374 FRunning := True; 375 end; 376 377 procedure TModule.BeforeStop; 378 begin 379 if not Running then Exit; 380 FRunning := False; 381 Manager.StopDependencies(Identification); 382 end; 383 384 procedure TModule.AfterStop; 385 begin 386 end; 387 320 388 procedure TModule.SetInstalled(AValue: Boolean); 321 389 begin … … 324 392 end; 325 393 394 procedure TModule.SetEnabled(AValue: Boolean); 395 begin 396 if FEnabled = AValue then Exit; 397 FEnabled := AValue; 398 if not FEnabled and FInstalled then Uninstall; 399 end; 400 326 401 procedure TModule.Start; 327 402 begin 328 if Running then Exit;329 Manager.StartDependencies(Identification, Dependencies);330 FRunning := True;403 BeforeStart; 404 // Do something 405 AfterStart; 331 406 end; 332 407 333 408 procedure TModule.Stop; 334 409 begin 335 if not Running then Exit;336 Manager.StopDependencies(Identification);337 FRunning := False;410 BeforeStop; 411 // Do something 412 AfterStop; 338 413 end; 339 414 … … 403 478 begin 404 479 Running := False; 405 Description.Free;406 Dependencies.Free;407 inherited Destroy;480 FreeAndNil(FDescription); 481 FreeAndNil(FDependencies); 482 inherited; 408 483 end; 409 484
Note:
See TracChangeset
for help on using the changeset viewer.