-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobalSetupGitExcel.bat
105 lines (85 loc) · 3.09 KB
/
globalSetupGitExcel.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
@ECHO OFF
REM Developed by TinToSer(https://github.com/tintoser) and Muffexx (https://github.com/Muffexx)
ECHO -Starting Global Setup
SET userGitConfigPath="%homedrive%%homepath%\.gitconfig"
SET gitExcelPath="%cd%\gitExcel.cmd"
REM Search for AppVLP.exe and SPREADSHEETCOMPARE.EXE in predefined paths
ECHO --Searching AppVLP.exe and SPREADSHEETCOMPARE.EXE
SET appVlpPath=
FOR %%p IN (
"C:\Program Files\Microsoft Office\root\Client",
"C:\Program Files (x86)\Microsoft Office\root\Client"
) DO (
CALL :CheckPath "%%~p\AppVLP.exe" appVlpPath
)
IF "%appVlpPath%"=="" (
ECHO ---AppVLP.exe NOT FOUND in predefined paths
GOTO :waitAndExitUnsuccessful
)
SET appVlpPath="%appVlpPath%"
ECHO ---Found: %appVlpPath%
SET spreadsheetComparePath=
FOR %%p IN (
"C:\Program Files\Microsoft Office\root\vfs\ProgramFilesX86\Microsoft Office\Office16\DCF",
"C:\Program Files (x86)\Microsoft Office\Office15\DCF",
"C:\Program Files (x86)\Microsoft Office\Office16\DCF",
"C:\Program Files (x86)\Microsoft Office\root\Office16\DCF"
) DO (
CALL :CheckPath "%%~p\SPREADSHEETCOMPARE.EXE" spreadsheetComparePath
)
IF "%spreadsheetComparePath%"=="" (
ECHO ---SPREADSHEETCOMPARE.EXE NOT FOUND in predefined paths
GOTO :waitAndExitUnsuccessful
)
SET spreadsheetComparePath="%spreadsheetComparePath%"
ECHO ---Found: %spreadsheetComparePath%
REM Writing gitExcel section to .gitconfig
ECHO --Updating user .gitconfig
SET "gitConfigDiffText=[diff "gitExcel"]"
SET "gitConfigCommandText= command = %gitExcelPath:\=/%"
FINDSTR /R /C:"^%gitConfigDiffText%" %userGitConfigPath% >NUL
IF ERRORLEVEL 1 (
ECHO %gitConfigDiffText%>> %userGitConfigPath%
ECHO ---Added: %gitConfigDiffText%
ECHO %gitConfigCommandText%>> %userGitConfigPath%
ECHO ---Added: %gitConfigCommandText%
) ELSE (
ECHO ---.gitconfig already contains %gitConfigDiffText% section
)
REM Replace paths in gitExcel.cmd
ECHO --Updating %gitExcelPath%
CALL :UpdateGitExcelFile %gitExcelPath%
GOTO :waitAndExitSuccessful
REM Function returns the name if the file exists
:CheckPath
IF EXIST "%~1" (
SET "%2=%~1")
GOTO :EOF
REM Search for "SET appVlpPath/spreadsheetComparePath" and replace the lines with the found paths
:UpdateGitExcelFile
SET filePath=%1
SET tempFilePath="%cd%\temp.cmd"
SET "_findVlpVar=SET appVlpPath="
SET "_findSscVar=SET spreadsheetComparePath="
SET "_setVlpVar=SET appVlpPath=%appVlpPath%"
SET "_setSscVar=SET spreadsheetComparePath=%spreadsheetComparePath%"
(FOR /f "delims=" %%l IN ('findstr /n "^" %filePath%') DO (
SET "Line=%%l"
for /F "delims=:" %%n in ("%%l") do set "LNum=%%n"
SETLOCAL ENABLEDELAYEDEXPANSION
SET "Line=!Line:*:=!"
IF "!Line:~0,15!"=="%_findVlpVar%" SET "Line=!_setVlpVar!"
IF "!Line:~0,27!"=="%_findSscVar%" SET "Line=!_setSscVar!"
ECHO(!Line!
ENDLOCAL
))> %tempFilePath%
MOVE /Y %tempFilePath% %filePath%
GOTO :EOF
:waitAndExitSuccessful
ECHO -Finished Global Setup
TIMEOUT /T 10
EXIT /B 0
:waitAndExitUnsuccessful
ECHO -Global Setup FAILED
TIMEOUT /T 10
EXIT /B 1