Skip to content

Commit

Permalink
Add ISS based installer
Browse files Browse the repository at this point in the history
  • Loading branch information
bozbez committed Aug 18, 2021
1 parent cafd24a commit 6c837eb
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 9 deletions.
68 changes: 68 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
cmake_minimum_required(VERSION 3.20)
project(win-capture-audio VERSION 1.0.0)

set(PLUGIN_AUTHOR "bozbez")
set(RELEASE_DIR "${PROJECT_SOURCE_DIR}/release")

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(ARCH_NAME "64bit")
else()
set(ARCH_NAME "32bit")
endif()

configure_file(
installer/installer.iss.in
../installer/installer.generated.iss
)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
find_package(LibObs REQUIRED)

Expand All @@ -14,6 +28,60 @@ set(win-capture-audio_SOURCES
add_library(win-capture-audio MODULE ${win-capture-audio_SOURCES})
target_link_libraries(win-capture-audio libobs dwmapi psapi ksuser)


add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD
COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E make_directory
"${RELEASE_DIR}/data/obs-plugins/${CMAKE_PROJECT_NAME}"
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
)

COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E copy_directory
"${PROJECT_SOURCE_DIR}/data"
"${RELEASE_DIR}/data/obs-plugins/${CMAKE_PROJECT_NAME}"
)

COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:${CMAKE_PROJECT_NAME}>"
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
)

COMMAND if $<CONFIG:RelWithDebInfo>==1 (
"${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE_BASE_NAME:${CMAKE_PROJECT_NAME}>.pdb"
"${RELEASE_DIR}/obs-plugins/${ARCH_NAME}"
)

VERBATIM
)

function(copy_helper_lib)
set(DATA_DIR "${RELEASE_DIR}/data/obs-plugins/${CMAKE_PROJECT_NAME}")
add_custom_command(TARGET ${ARGV0} POST_BUILD
COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E make_directory
"${RELEASE_DIR}/data/obs-plugins/${CMAKE_PROJECT_NAME}"
)

COMMAND if $<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>==1 (
"${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE:${ARGV0}>"
"${RELEASE_DIR}/data/obs-plugins/${CMAKE_PROJECT_NAME}"
)

COMMAND if $<CONFIG:RelWithDebInfo>==1 (
"${CMAKE_COMMAND}" -E copy
"$<TARGET_FILE_BASE_NAME:${ARGV0}>.pdb"
"${RELEASE_DIR}/data/obs-plugins/${CMAKE_PROJECT_NAME}"
)

VERBATIM
)
endfunction()


add_subdirectory(src/get-audio-offsets)
add_subdirectory(src/audio-hook)
add_subdirectory(src/inject-helper)
Expand Down
106 changes: 106 additions & 0 deletions installer/installer.iss.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
; Based on https://github.com/obsproject/obs-amd-encoder/blob/master/ci/installer.in.iss

#define MyAppName "@CMAKE_PROJECT_NAME@"
#define MyAppVersion "@CMAKE_PROJECT_VERSION@"
#define MyAppPublisher "@PLUGIN_AUTHOR@"
#define MyAppURL "https://github.com/bozbez/win-capture-audio"

[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={{406FD363-BC38-47EE-AF53-7F6FB4D56ECE}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={code:GetDirName}
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
LicenseFile="@PROJECT_SOURCE_DIR@/LICENSE"
OutputBaseFilename={#MyAppName}-{#MyAppVersion}-setup
Compression=lzma
SolidCompression=yes
VersionInfoVersion={#MyAppVersion}
VersionInfoCompany={#MyAppPublisher}
VersionInfoDescription={#MyAppName} Setup

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "@RELEASE_DIR@/*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

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

[Code]
function GetDirName(Value: string): string;
var
InstallPath: string;
begin
// Initialize default path, which will be returned when the following registry
// key queries fail due to missing keys or for some different reason
Result := '{pf}\obs-studio';
// Query the first registry value; if this succeeds, return the obtained value
if RegQueryStringValue(HKLM32, 'SOFTWARE\OBS Studio', '', InstallPath) then
Result := InstallPath
end;

function GetUninstallString(): String;
var
sUnInstPath: String;
sUnInstallString: String;
begin
sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');
sUnInstallString := '';
if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
Result := sUnInstallString;
end;

function IsUpgrade(): Boolean;
begin
Result := (GetUninstallString() <> '');
end;

function UnInstallOldVersion(): Integer;
var
sUnInstallString: String;
iResultCode: Integer;
begin
// Return Values:
// 1 - uninstall string is empty
// 2 - error executing the UnInstallString
// 3 - successfully executed the UnInstallString

// default return value
Result := 0;

// get the uninstall string of the old app
sUnInstallString := GetUninstallString();
if sUnInstallString <> '' then begin
sUnInstallString := RemoveQuotes(sUnInstallString);
if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
Result := 3
else
Result := 2;
end else
Result := 1;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
if (CurStep=ssInstall) then
begin
if (IsUpgrade()) then
begin
UnInstallOldVersion();
end;
end;
end;
8 changes: 5 additions & 3 deletions src/audio-hook/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ target_include_directories(audio-hook PUBLIC ${DETOURS_INCLUDE_DIR})
target_link_libraries(audio-hook ${DETOURS_LIBRARIES} psapi)

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_output_suffix "64")
set(_output_suffix "64")
else()
set(_output_suffix "32")
set(_output_suffix "32")
endif()

set_target_properties(audio-hook
PROPERTIES OUTPUT_NAME "audio-hook${_output_suffix}")
PROPERTIES OUTPUT_NAME "audio-hook${_output_suffix}")

copy_helper_lib(audio-hook)
8 changes: 5 additions & 3 deletions src/get-audio-offsets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ add_executable(get-audio-offsets ${get-audio-offsets_SOURCES})
target_link_libraries(get-audio-offsets mmdevapi.lib)

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_output_suffix "64")
set(_output_suffix "64")
else()
set(_output_suffix "32")
set(_output_suffix "32")
endif()

set_target_properties(get-audio-offsets PROPERTIES
OUTPUT_NAME "get-audio-offsets${_output_suffix}")
OUTPUT_NAME "get-audio-offsets${_output_suffix}")

copy_helper_lib(get-audio-offsets)
8 changes: 5 additions & 3 deletions src/inject-helper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ add_executable(inject-helper
${inject-helper_SOURCES})

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_output_suffix "64")
set(_output_suffix "64")
else()
set(_output_suffix "32")
set(_output_suffix "32")
endif()

set_target_properties(inject-helper
PROPERTIES OUTPUT_NAME "inject-helper${_output_suffix}")
PROPERTIES OUTPUT_NAME "inject-helper${_output_suffix}")

copy_helper_lib(inject-helper)

0 comments on commit 6c837eb

Please sign in to comment.