Changeset 428 for ModularSystem/UModularSystem.pas
- Timestamp:
- Oct 9, 2012, 11:48:44 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ModularSystem/UModularSystem.pas
r421 r428 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; … … 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 51 58 property Version: string read FVersion write FVersion; … … 79 86 procedure EnumModulesInstall(Dependencies, ModuleList: TStringList); 80 87 procedure EnumModulesUninstall(ModuleName: string; ModuleList: TStringList); 81 procedure RegisterModule(Module: TModule; MarkForInstall: Boolean = False);88 procedure RegisterModule(Module: TModule; Enabled: Boolean = True); 82 89 procedure UnregisterModule(Module: TModule); 83 90 procedure StartInstalled; 84 procedure Install Marked;91 procedure InstallEnabled; 85 92 procedure StopAll; 86 93 procedure UninstallAll; 94 procedure LoadFromRegistry(Context: TRegistryContext); 95 procedure SaveToRegistry(Context: TRegistryContext); 87 96 constructor Create(AOwner: TComponent); override; 88 97 destructor Destroy; override; … … 143 152 for I := 0 to Dependencies.Count - 1 do begin 144 153 Module := FindModuleByName(Dependencies[I]); 145 if Assigned(Module) then begin154 if Assigned(Module) and Module.Enabled then begin 146 155 if not Module.Running then Module.Start; 147 156 end else raise Exception.CreateFmt(SModuleNotFound, [ModuleName, Dependencies[I]]); … … 199 208 for I := 0 to Dependencies.Count - 1 do begin 200 209 Module := FindModuleByName(Dependencies[I]); 201 if Assigned(Module) then begin210 if Assigned(Module) and Module.Enabled then begin 202 211 if not Module.Installed then Module.Install; 203 212 end else raise Exception.CreateFmt(SModuleNotFound, [ModuleName, Dependencies[I]]); … … 248 257 249 258 procedure TModuleManager.RegisterModule(Module: TModule; 250 MarkForInstall: Boolean = False);259 Enabled: Boolean = True); 251 260 begin 252 261 Modules.Add(Module); 253 262 Module.Manager := Self; 254 263 Module.API := API; 255 Module. MarkForInstall := MarkForInstall;264 Module.Enabled := Enabled; 256 265 end; 257 266 … … 270 279 end; 271 280 272 procedure TModuleManager.Install Marked;281 procedure TModuleManager.InstallEnabled; 273 282 var 274 283 I: Integer; … … 276 285 for I := 0 to Modules.Count - 1 do 277 286 with TModule(Modules[I]) do 278 if not Installed and MarkForInstallthen Install;287 if not Installed and Enabled then Install; 279 288 end; 280 289 … … 310 319 end; 311 320 321 procedure TModuleManager.LoadFromRegistry(Context: TRegistryContext); 322 var 323 I: Integer; 324 begin 325 with TRegistryEx.Create do 326 try 327 RootKey := Context.RootKey; 328 for I := 0 to Modules.Count - 1 do 329 with TModule(Modules[I]) do begin 330 OpenKey(Context.Key + '\' + Identification, True); 331 Running := ReadBoolWithDefault('Run', Enabled); 332 end; 333 finally 334 Free; 335 end; 336 end; 337 338 procedure TModuleManager.SaveToRegistry(Context: TRegistryContext); 339 var 340 I: Integer; 341 begin 342 with TRegistryEx.Create do 343 try 344 RootKey := Context.RootKey; 345 for I := 0 to Modules.Count - 1 do 346 with TModule(Modules[I]) do begin 347 OpenKey(Context.Key + '\' + Identification, True); 348 WriteBool('Run', Running); 349 end; 350 finally 351 Free; 352 end; 353 end; 354 312 355 { TModule } 313 356 … … 318 361 end; 319 362 363 procedure TModule.BeforeStart; 364 begin 365 if Running then Exit; 366 if not Installed then Install; 367 Manager.StartDependencies(Identification, Dependencies); 368 end; 369 370 procedure TModule.AfterStart; 371 begin 372 FRunning := True; 373 end; 374 375 procedure TModule.BeforeStop; 376 begin 377 if not Running then Exit; 378 FRunning := False; 379 Manager.StopDependencies(Identification); 380 end; 381 382 procedure TModule.AfterStop; 383 begin 384 end; 385 320 386 procedure TModule.SetInstalled(AValue: Boolean); 321 387 begin … … 324 390 end; 325 391 392 procedure TModule.SetEnabled(AValue: Boolean); 393 begin 394 if FEnabled = AValue then Exit; 395 FEnabled := AValue; 396 if not FEnabled and FInstalled then Uninstall; 397 end; 398 326 399 procedure TModule.Start; 327 400 begin 328 if Running then Exit; 329 Manager.StartDependencies(Identification, Dependencies); 330 FRunning := True; 401 BeforeStart; 402 AfterStart; 331 403 end; 332 404 333 405 procedure TModule.Stop; 334 406 begin 335 if not Running then Exit; 336 Manager.StopDependencies(Identification); 337 FRunning := False; 407 BeforeStop; 408 AfterStop; 338 409 end; 339 410
Note:
See TracChangeset
for help on using the changeset viewer.