Skip to content

Commit

Permalink
Merge pull request #12 from viniciussanchez/master
Browse files Browse the repository at this point in the history
Added exception message on remove bpl
  • Loading branch information
viniciussanchez authored May 12, 2020
2 parents c291474 + e1c70b0 commit 6270cc0
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 79 deletions.
Binary file removed boss_ide.res
Binary file not shown.
3 changes: 1 addition & 2 deletions src/IDE/Boss.IDE.BossInstall.pas
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ interface
TMenuNotifierBossInstall = class(TNotifierObject, IOTANotifier, IOTAProjectMenuItemCreatorNotifier)
public
function CanHandle(const Ident: string): Boolean;
procedure AddMenu(const Project: IOTAProject; const IdentList: TStrings;
const ProjectManagerMenuList: IInterfaceList; IsMultiSelect: Boolean);
procedure AddMenu(const Project: IOTAProject; const IdentList: TStrings; const ProjectManagerMenuList: IInterfaceList; IsMultiSelect: Boolean);
end;

TButtonBoss = class(TNotifierObject, IOTALocalMenu, IOTAProjectManagerMenu)
Expand Down
17 changes: 9 additions & 8 deletions src/IDE/Boss.IDE.Installer.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

interface

uses
ToolsApi;
uses ToolsApi;

type
TBossIDEInstaller = class
Expand All @@ -14,10 +13,7 @@ TBossIDEInstaller = class

implementation

uses
System.Classes, Providers.Message, System.SysUtils;

{ TBossIDEInstaller }
uses System.Classes, Providers.Message, System.SysUtils;

class function TBossIDEInstaller.InstallBpl(const AFile: string): Boolean;
var
Expand All @@ -32,7 +28,7 @@ class function TBossIDEInstaller.InstallBpl(const AFile: string): Boolean;
except
on E: Exception do
begin
TProviderMessage.GetInstance.WriteLn('Failed to load ' + AFile);
TProviderMessage.GetInstance.WriteLn('Failed to install ' + AFile);
TProviderMessage.GetInstance.WriteLn(#10 + E.Message);
LResult := False;
end;
Expand All @@ -51,7 +47,12 @@ class function TBossIDEInstaller.RemoveBpl(const AFile: string): Boolean;
LResult := (BorlandIDEServices as IOTAPAckageServices).UninstallPackage(AFile)
end);
except
LResult := False;
on E: Exception do
begin
TProviderMessage.GetInstance.WriteLn('Failed to remove ' + AFile);
TProviderMessage.GetInstance.WriteLn(#10 + E.Message);
LResult := False;
end;
end;
Result := LResult;
end;
Expand Down
12 changes: 2 additions & 10 deletions src/IDE/Boss.IDE.PojectListener.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

interface

uses
ToolsAPI, System.Generics.Collections, System.SysUtils;
uses ToolsAPI, System.Generics.Collections, System.SysUtils;

type
TBossProjectListener = class(TNotifierObject, IOTAIDENotifier)
Expand All @@ -21,7 +20,6 @@ TBossProjectListener = class(TNotifierObject, IOTAIDENotifier)
procedure Modified;
constructor Create;
public

procedure AddListener(AType: TOTAFileNotification; ACallback: TProc<string>);
procedure RemoveListener(AType: TOTAFileNotification; ACallback: TProc<string>);
class function GetInstance: TBossProjectListener;
Expand All @@ -30,14 +28,11 @@ TBossProjectListener = class(TNotifierObject, IOTAIDENotifier)

implementation

uses
Winapi.Windows;
uses Winapi.Windows;

var
FInstance: TBossProjectListener;

{ TBossProjectListener }

procedure TBossProjectListener.AddListener(AType: TOTAFileNotification; ACallback: TProc<string>);
var
LListeners: TList<TProc<string>>;
Expand Down Expand Up @@ -93,7 +88,6 @@ procedure TBossProjectListener.FileNotification(NotifyCode: TOTAFileNotification
begin
if not FListeners.TryGetValue(NotifyCode, LListeners) then
Exit;

for LCallback in LListeners do
begin
LCallback(FileName);
Expand All @@ -117,9 +111,7 @@ procedure TBossProjectListener.RemoveListener(AType: TOTAFileNotification; ACall
LListeners: TList<TProc<string>>;
begin
if FListeners.TryGetValue(AType, LListeners) then
begin
LListeners.Remove(ACallback);
end;
end;

end.
12 changes: 2 additions & 10 deletions src/IDE/Boss.IDE.Register.pas
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ procedure Register;

implementation

uses
ToolsAPI, Winapi.Windows, Boss.IDE.BossInstall, Boss.IDE.PojectListener, Boss.Modules.PackageProcessor,
Vcl.Graphics, DesignIntf, System.Types, Providers.Logo, Providers.Message, Boss.Ide.OpenToolApi.Tools;
uses ToolsAPI, Winapi.Windows, Boss.IDE.BossInstall, Boss.IDE.PojectListener, Boss.Modules.PackageProcessor, Vcl.Graphics,
DesignIntf, System.Types, Providers.Logo, Providers.Message, Boss.Ide.OpenToolApi.Tools;

const
C_INVALID_NOTIFIER = -1;
Expand Down Expand Up @@ -39,18 +38,11 @@ procedure Register;
end;

LProjectManager := (BorlandIDEServices as IOTAProjectManager);

LServices := (BorlandIDEServices as IOTAServices);


LMessageServices := (BorlandIDEServices as IOTAMessageServices);

FNotifierMenuIndex := LProjectManager.AddMenuItemCreatorNotifier(TMenuNotifierBossInstall.Create);

FNotifierProjectIndex := LServices.AddNotifier(TBossProjectListener.GetInstance);

TProviderMessage.GetInstance.Initialize(LMessageServices);

TBossProjectListener.GetInstance.AddListener(ofnActiveProjectChanged, TBossPackageProcessor.OnActiveProjectChanged);
end;

Expand Down
53 changes: 20 additions & 33 deletions src/core/Boss.Modules.PackageProcessor.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

interface

uses
System.IniFiles, System.Classes, System.Types;
uses System.IniFiles, System.Classes, System.Types;

type
TBossPackageProcessor = class
Expand All @@ -29,22 +28,18 @@ TBossPackageProcessor = class
procedure LoadBpls;
procedure UnloadOlds;

class Procedure OnActiveProjectChanged(AProject: string);
class procedure OnActiveProjectChanged(AProject: string);
class function GetInstance: TBossPackageProcessor;
end;


const
BPLS = 'BPLS';
DELIMITER = ';';

implementation

uses
System.IOUtils, Providers.Consts, Boss.IDE.Installer, Providers.Message, Vcl.Dialogs, ToolsAPI,
Boss.IDE.OpenToolApi.Tools, Winapi.ShellAPI, Winapi.Windows, Vcl.Menus, Boss.EventWrapper, Vcl.Forms, System.SysUtils;

{ TBossPackageProcessor }
uses System.IOUtils, Providers.Consts, Boss.IDE.Installer, Providers.Message, Vcl.Dialogs, ToolsAPI, Boss.IDE.OpenToolApi.Tools,
Winapi.ShellAPI, Winapi.Windows, Vcl.Menus, Boss.EventWrapper, Vcl.Forms, System.SysUtils;

var
_Instance: TBossPackageProcessor;
Expand All @@ -53,15 +48,14 @@ procedure ExecuteAndWait(const ACommand: string);
var
LStartup: TStartupInfo;
LProcess: TProcessInformation;
LProgram: String;
LProgram: string;
begin
LProgram := Trim(ACommand);
FillChar(LStartup, SizeOf(LStartup), 0);
LStartup.cb := SizeOf(TStartupInfo);
LStartup.wShowWindow := SW_HIDE;

if CreateProcess(nil, pchar(LProgram), nil, nil, true, CREATE_NO_WINDOW,
nil, nil, LStartup, LProcess) then
if CreateProcess(nil, pchar(LProgram), nil, nil, true, CREATE_NO_WINDOW, nil, nil, LStartup, LProcess) then
begin
while WaitForSingleObject(LProcess.hProcess, 10) > 0 do
begin
Expand All @@ -71,15 +65,12 @@ procedure ExecuteAndWait(const ACommand: string);
CloseHandle(LProcess.hThread);
end
else
begin
RaiseLastOSError;
end;
end;

function TBossPackageProcessor.GetEnv(AEnv: string): string;
begin
Result := FHomeDrive + FHomePath + TPath.DirectorySeparatorChar + C_BOSS_CACHE_FOLDER + TPath.DirectorySeparatorChar
+ C_ENV + AEnv;
Result := FHomeDrive + FHomePath + TPath.DirectorySeparatorChar + C_BOSS_CACHE_FOLDER + TPath.DirectorySeparatorChar + C_ENV + AEnv;
end;

procedure DeleteDirectory(const DirName: string);
Expand All @@ -88,14 +79,14 @@ procedure DeleteDirectory(const DirName: string);
begin
FillChar(FileOp, SizeOf(FileOp), 0);
FileOp.wFunc := FO_DELETE;
FileOp.pFrom := PChar(DirName+#0);
FileOp.pFrom := pchar(DirName + #0);
FileOp.fFlags := FOF_SILENT or FOF_NOERRORUI or FOF_NOCONFIRMATION;
SHFileOperation(FileOp);
end;

procedure TBossPackageProcessor.MakeLink(AProjectPath, AEnv: string);
var
LCommand: PChar;
LCommand: pchar;
LFile: string;
begin
try
Expand All @@ -106,9 +97,8 @@ procedure TBossPackageProcessor.MakeLink(AProjectPath, AEnv: string);

for LFile in TDirectory.GetFiles(AProjectPath + TPath.DirectorySeparatorChar + C_MODULES_FOLDER + '.' + AEnv) do
begin
TFile.Copy(LFile, TPath.Combine(GetEnv(AEnv), TPath.GetFileName(LFile)), True);
TFile.Copy(LFile, TPath.Combine(GetEnv(AEnv), TPath.GetFileName(LFile)), true);
end;

except
on E: Exception do
TProviderMessage.GetInstance.WriteLn('Failed on make link: ' + E.Message);
Expand All @@ -126,7 +116,7 @@ constructor TBossPackageProcessor.Create;

if not FDataFile.Values[BPLS].IsEmpty then
begin
FDataFile.Delimiter := ';';
FDataFile.DELIMITER := ';';
FDataFile.DelimitedText := FDataFile.Values[BPLS];
end;

Expand All @@ -151,11 +141,10 @@ function TBossPackageProcessor.GetBplList: TStringDynArray;
LIndex: Integer;
I: Integer;
begin
Result := Nil;
Result := nil;
if not DirectoryExists(GetEnv(C_ENV_BPL)) then
Exit();


LOrderFileName := GetEnv(C_ENV_BPL) + TPath.DirectorySeparatorChar + C_BPL_ORDER;
if FileExists(LOrderFileName) then
begin
Expand All @@ -178,8 +167,7 @@ function TBossPackageProcessor.GetBplList: TStringDynArray;

function TBossPackageProcessor.GetDataCachePath: string;
begin
Result := FHomeDrive + FHomePath + TPath.DirectorySeparatorChar +
C_BOSS_CACHE_FOLDER + TPath.DirectorySeparatorChar + C_DATA_FILE;
Result := FHomeDrive + FHomePath + TPath.DirectorySeparatorChar + C_BOSS_CACHE_FOLDER + TPath.DirectorySeparatorChar + C_DATA_FILE;
end;

class function TBossPackageProcessor.GetInstance: TBossPackageProcessor;
Expand Down Expand Up @@ -223,7 +211,7 @@ procedure TBossPackageProcessor.DoLoadBpls(ABpls: TStringDynArray);
on E: Exception do
begin
TProviderMessage.GetInstance.WriteLn('Failed to get info of ' + LBpl);
TProviderMessage.GetInstance.WriteLn(#10 + E.message);
TProviderMessage.GetInstance.WriteLn(#10 + E.Message);
LBplsRedo := LBplsRedo + [LBpl];
Continue;
end;
Expand All @@ -235,13 +223,13 @@ procedure TBossPackageProcessor.DoLoadBpls(ABpls: TStringDynArray);
begin
TProviderMessage.GetInstance.WriteLn('Instaled: ' + LBpl);
FDataFile.Add(LBpl);
LInstalledNew := True;
LInstalledNew := true;
end
else
LBplsRedo := LBplsRedo + [LBpl];
end;
end;

SaveData;

if LInstalledNew then
Expand Down Expand Up @@ -291,7 +279,7 @@ class procedure TBossPackageProcessor.OnActiveProjectChanged(AProject: string);
end;

procedure TBossPackageProcessor.SaveData;
begin
begin
FDataFile.SaveToFile(GetDataCachePath);
end;

Expand All @@ -309,9 +297,9 @@ procedure TBossPackageProcessor.UnloadOlds;
Application.ProcessMessages;
end;

FDataFile.Clear;
FDataFile.Clear;
SaveData;

LMenu := NativeServices.MainMenu.Items.Find('Tools');

NativeServices.MenuBeginUpdate;
Expand All @@ -333,7 +321,6 @@ procedure TBossPackageProcessor.UnloadOlds;
initialization

finalization

_Instance.Free;
_Instance.Free;

end.
14 changes: 6 additions & 8 deletions src/core/wrapper/Boss.Commands.pas
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

interface

uses
Vcl.StdCtrls;
uses Vcl.StdCtrls;

procedure Runner(ACommand, APath: string; ALoadPackages: Boolean);

procedure RunBossInstall(APath: string; ALoadPackages: Boolean);

implementation

uses
Winapi.Windows, Vcl.Forms, System.SysUtils, System.Classes, System.Threading, Providers.Message,
uses Winapi.Windows, Vcl.Forms, System.SysUtils, System.Classes, System.Threading, Providers.Message,
Boss.Modules.PackageProcessor, DosCommand;

procedure RunBossInstall(APath: string; ALoadPackages: Boolean);
Expand All @@ -25,12 +22,14 @@ procedure Runner(ACommand, APath: string; ALoadPackages: Boolean);
LDosCommand: TDosCommand;
begin
LDosCommand := TDosCommand.Create(nil);
LDosCommand.OnNewLine := procedure(ASender: TObject; const ANewLine: string; AOutputType: TOutputType)
LDosCommand.OnNewLine :=
procedure(ASender: TObject; const ANewLine: string; AOutputType: TOutputType)
begin
TProviderMessage.GetInstance.WriteLn(ANewLine);
end;

LDosCommand.OnTerminated := procedure(ASender: TObject)
LDosCommand.OnTerminated :=
procedure(ASender: TObject)
begin
LDosCommand.Free;
if ALoadPackages then
Expand All @@ -43,7 +42,6 @@ procedure Runner(ACommand, APath: string; ALoadPackages: Boolean);
LDosCommand.CurrentDir := APath;
LDosCommand.CommandLine := ACommand;
LDosCommand.Execute;

end;

end.
Loading

0 comments on commit 6270cc0

Please sign in to comment.