@@ -57,16 +57,38 @@ function CopyManifestFile () {
57
57
}
58
58
59
59
const getBraveCoreInstallerPath = ( ) => {
60
+ const os = require ( 'os' )
60
61
const appDir = getBraveBinPath ( )
61
- return path . join ( appDir , 'resources' , 'BraveBrowserSetup.exe' )
62
+ return path . join ( appDir , 'resources' ,
63
+ os . arch ( ) === 'x32' ? 'BraveBrowserSetup32.exe' : 'BraveBrowserSetup64.exe' )
62
64
}
63
65
64
66
function InstallBraveCore ( ) {
65
- // TODO(bsclifton): get a proper version of the omaha installer
66
- // (built using https://github.com/brave/devops/pull/335)
67
- //const cmd = getBraveCoreInstallerPath() + " /silent /install"
68
- const cmd = getBraveCoreInstallerPath ( ) + " /install"
67
+ const fs = require ( 'fs' )
68
+
69
+ // expected install paths
70
+ const braveCoreInstallLocations = [
71
+ '%USERPROFILE%\\AppData\\Local\\BraveSoftware\\Brave-Browser\\Application' ,
72
+ '%ProgramFiles(x86)%\\BraveSoftware\\Brave-Browser\\Application' ,
73
+ '%ProgramFiles%\\BraveSoftware\\Brave-Browser\\Application'
74
+ ]
75
+
76
+ // check for existing installations
77
+ for ( let i = 0 ; i < braveCoreInstallLocations . length ; i ++ ) {
78
+ const path = braveCoreInstallLocations [ i ]
79
+ const resolvedPath = path . replace ( / % ( [ ^ % ] + ) % / g, function ( _ , variableToResolve ) {
80
+ return process . env [ variableToResolve ]
81
+ } )
82
+ if ( fs . existsSync ( resolvedPath ) ) {
83
+ return false
84
+ }
85
+ }
86
+
87
+ // brave-core is not installed; go ahead with silent install
88
+ const cmd = getBraveCoreInstallerPath ( ) + " /silent /install"
69
89
execSync ( cmd )
90
+
91
+ return true
70
92
}
71
93
72
94
// windows installation events etc...
@@ -94,22 +116,21 @@ if (process.platform === 'win32') {
94
116
CopyManifestFile ( )
95
117
// Launch defaults helper to add defaults on install
96
118
spawn ( getBraveDefaultsBinPath ( ) , [ ] , { detached : true } )
97
- // Silent install brave-core
98
- // TODO(bsclifton):
99
- // - don't install if already installed
100
- // - verify this doesn't run twice AND that it doesn't run on uninstall
101
- InstallBraveCore ( )
102
- // relaunch and append argument expected in:
103
- // https://github.com/brave/brave-browser/issues/1545
104
- app . relaunch ( { args : [ '--relaunch' , '--upgrade-from-muon' ] } )
105
- app . exit ( )
106
- return
107
-
108
119
} else if ( isSquirrelUninstall ) {
109
120
// Launch defaults helper to remove defaults on uninstall
110
121
// Sync to avoid file path in use on uninstall
111
122
spawnSync ( getBraveDefaultsBinPath ( ) , [ '-uninstall' ] )
112
123
}
124
+ // silent install brave-core
125
+ if ( isSquirrelFirstRun || isSquirrelInstall || isSquirrelUpdate ) {
126
+ if ( InstallBraveCore ( ) ) {
127
+ // relaunch and append argument expected in:
128
+ // https://github.com/brave/brave-browser/issues/1545
129
+ app . relaunch ( { args : [ '--relaunch' , '--upgrade-from-muon' ] } )
130
+ app . exit ( )
131
+ return
132
+ }
133
+ }
113
134
114
135
if ( shouldQuit ( channel ) ) {
115
136
process . exit ( 0 )
0 commit comments