Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,13 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd

# Installer projects output
*.msi
*.exe
AssetManager.installer/Output

# Env
.Env
AssetManager.tray/appsettings.json
172 changes: 172 additions & 0 deletions AssetManager.installer/setup.iss
Comment thread
glauberx86 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
; Non-commercial use only

#define MyAppName "AssetManager"
#define MyAppVersion "1.0.2"
#define MyAppPublisher "Borgno"
#define MyAppExeName "AssetManager.tray.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{8E2374B6-2EE6-4C3A-B17A-AF32C9565CB1}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName={autopf}\{#MyAppPublisher}\{#MyAppName}
DisableDirPage=yes
UninstallDisplayIcon={app}\{#MyAppExeName}
; "ArchitecturesAllowed=x64compatible" specifies that Setup cannot run
; on anything but x64 and Windows 11 on Arm.
ArchitecturesAllowed=x64compatible
; "ArchitecturesInstallIn64BitMode=x64compatible" requests that the
; install be done in "64-bit mode" on x64 or Windows 11 on Arm,
; meaning it should use the native 64-bit Program Files directory and
; the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64compatible
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only).
;PrivilegesRequired=lowest
OutputDir=Output
OutputBaseFilename=assetmanager_installer
Compression=lzma
SolidCompression=yes
WizardStyle=modern dynamic windows11

[Languages]
Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl"

[Files]
Source: "C:\Users\GYNTI-N03.GYNTI-N03\source\repos\AssetManager\AssetManager.tray\bin\Release\net10.0-windows\win-x64\*"; \
DestDir: "{app}\tray"; Flags: ignoreversion; \
Excludes: "appsettings.json, appsettings_example.json"

Source: "C:\Users\GYNTI-N03.GYNTI-N03\source\repos\AssetManager\AssetManager.service\bin\Release\net10.0-windows\win-x64\*"; \
DestDir: "{app}\service"; Flags: ignoreversion

Source: "C:\Users\GYNTI-N03.GYNTI-N03\source\repos\AssetManager\AssetManager.tray\bin\Release\net10.0-windows\win-x64\appsettings_example.json"; \
DestDir: "{app}\tray"; \
DestName: "appsettings.json"; Flags: ignoreversion
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

; [Icons]
; Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
; Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"

[Run]
Filename: "sc.exe"; \
Parameters: "create AssetManager binPath= ""{app}\service\AssetManager.service.exe"" start= auto"; \
Flags: runhidden

Filename: "sc.exe"; \
Parameters: "start AssetManager"; \
Flags: runhidden

Filename: "schtasks.exe"; \
Parameters: "/create /f /sc onlogon /rl highest /ru SYSTEM /tn ""AssetManagerTray"" /tr ""\""{app}\tray\AssetManager.tray.exe\"" """; \
Flags: runhidden

Filename: "powershell.exe"; \
Parameters: "-ExecutionPolicy Bypass -Command ""$t = Get-ScheduledTask -TaskName 'AssetManagerTray'; $s = $t.Settings; $s.ExecutionTimeLimit = [TimeSpan]::Zero; $s.AllowStartIfOnBatteries = $true; $s.DontStopIfGoingOnBatteries = $true; Set-ScheduledTask -TaskName 'AssetManagerTray' -Settings $s"""; \
Flags: runhidden

; Iniciar o tray após a instalação
;Filename: "{app}\tray\{#MyAppExeName}"; \
;Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; \
;Flags: postinstall skipifsilent

[UninstallRun]
; Parar e remover serviço
Filename: "sc.exe"; Parameters: "stop AssetManager"; Flags: runhidden
Filename: "sc.exe"; Parameters: "delete AssetManager"; Flags: runhidden

; Remover tarefa agendada
Filename: "schtasks.exe"; Parameters: "/end /tn ""AssetManagerTray"""; Flags: runhidden
Filename: "schtasks.exe"; Parameters: "/delete /f /tn ""AssetManagerTray""" ; Flags: runhidden

[Code]
var
TokenPage: TInputQueryWizardPage;

procedure InitializeWizard;
begin
TokenPage := CreateInputQueryPage(wpWelcome,
'Configuração da API', 'Autenticação do Agente',
'Insira a URL e o Token de acesso da API para que o AssetManager possa enviar os dados.');
TokenPage.Add('URL da API:', False);
TokenPage.Add('API Token:', False);
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
if (PageID = TokenPage.ID) and FileExists(ExpandConstant('{src}\appsettings.json')) then
Result := True
else
Result := False;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
JsonDestino: String;
JsonOrigem: String;
FileContentAnsi: AnsiString;
FileContentString: String;
UserUrl: String;
UserToken: String;
HouveAlteracao: Boolean;
begin
if CurStep = ssPostInstall then
begin
JsonDestino := ExpandConstant('{app}\tray\appsettings.json');
JsonOrigem := ExpandConstant('{src}\appsettings.json');
HouveAlteracao := False;

if FileExists(JsonOrigem) then
begin
Log('Arquivo appsettings.json encontrado na origem. Copiando...');
if FileCopy(JsonOrigem, JsonDestino, False) then
Log('Configuração importada automaticamente.')
else
Log('Falha ao copiar configuração automática.');
end

else
begin
if (TokenPage <> nil) then
begin
UserUrl := TokenPage.Values[0];
UserToken := TokenPage.Values[1];
end
else
begin
UserUrl := '';
UserToken := '';
end;
if FileExists(JsonDestino) then
begin
if LoadStringFromFile(JsonDestino, FileContentAnsi) then
begin
FileContentString := String(FileContentAnsi);
if (UserUrl <> '') and (StringChange(FileContentString, '{{URL}}', UserUrl) > 0) then
begin
HouveAlteracao := True;
Log('URL atualizada.');
end;
if (UserToken <> '') and (StringChange(FileContentString, '{{TOKEN}}', UserToken) > 0) then
begin
HouveAlteracao := True;
Log('Token atualizado.');
end;
if HouveAlteracao then
begin
SaveStringToFile(JsonDestino, AnsiString(FileContentString), False);
Log('Arquivo JSON salvo com sucesso.');
end;
end;
end;
end;
end;
end;
9 changes: 6 additions & 3 deletions AssetManager.service/AssetManager.service.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Worker">
<Project Sdk="Microsoft.NET.Sdk.Worker">

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<TargetFramework>net10.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<SatelliteResourceLanguages>pt-BR</SatelliteResourceLanguages>
<UserSecretsId>dotnet-AssetManager-7dd1a0f1-3fce-4c35-bc7b-8f9a71a59f68</UserSecretsId>
<SelfContained>true</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="10.0.0" />
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="10.0.0" />
</ItemGroup>
</Project>
</Project>
1 change: 0 additions & 1 deletion AssetManager.service/README.md

This file was deleted.

29 changes: 29 additions & 0 deletions AssetManager.service/debug.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
param(
[string]$PipeName = "asset-monitor-pipe",
[int]$IntervalSeconds = 2
)

while ($true) {
Clear-Host
Write-Host "AssetManager Debug ($(Get-Date))"
Write-Host "-------------------------------"

try {
$pipe = New-Object System.IO.Pipes.NamedPipeClientStream(".", $PipeName, [System.IO.Pipes.PipeDirection]::In)
$pipe.Connect(3000)

$reader = New-Object System.IO.StreamReader($pipe)
$json = $reader.ReadLine()

$reader.Close()
$pipe.Close()

$obj = $json | ConvertFrom-Json
$obj | Format-List
}
catch {
Write-Host "Erro ao ler pipe: $_" -ForegroundColor Red
}

Start-Sleep -Seconds $IntervalSeconds
}
6 changes: 0 additions & 6 deletions AssetManager.service/package-lock.json

This file was deleted.

2 changes: 1 addition & 1 deletion AssetManager.service/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

builder.Services.AddWindowsService(options =>
{
options.ServiceName = "AssetManager";
options.ServiceName = "AssetManager";
});

builder.Services.AddSingleton<ICpuMonitor, CpuMonitor>();
Expand Down
Loading