@ECHO OFF

:SETSOURCEFOLDER
	REM Return the folder this batch file was launched from since the current
	REM directory will change if launched from a network share
	SET SOURCEFOLDER=%~dp0

:START
TITLE Alumi Icon Pack 7600 X86
CLS
ECHO.
ECHO.###########################################################
ECHO.##          Alumi Icon Pack 7600 X86 Installer           ##
ECHO.##     ---------------------------------------------     ##
ECHO.##                                                       ##
ECHO.##   DISABLE USER ACCOUNT CONTROL BEFORE PRESSING '1'!!  ##
ECHO.##                For more info on this,                 ##
ECHO.##   please press '3' then 'Enter' to view the Readme.   ##
ECHO.##                                                       ##
ECHO.##   Please also close all programs before proceeding.   ##
ECHO.##                                                       ##
ECHO.##                                                       ##
ECHO.##                                                       ##
ECHO.###########################################################
ECHO.
ECHO.
ECHO.Are you sure you want to install Alumi Icon Pack 7600 X86?
ECHO.
ECHO.----------- 
ECHO.1. Yes.
ECHO.2. No.
ECHO.3. View the 'readme.txt'.
ECHO.----------- 
set /p userinp=Please choose a number(1-3):
set userinp=%userinp:~0,1%
if "%userinp%"=="1" goto 1
if "%userinp%"=="2" goto 2
if "%userinp%"=="3" goto 3
echo invalid choice
goto start
:1
GOTO INSTALLSCRIPTBEGIN
:2
GOTO ALREADYPATCHEDEXIT
:3
cd\
NOTEPAD %SOURCEFOLDER%README.txt
GOTO JUSTEXIT


:INSTALLSCRIPTBEGIN
SET PATH1=%windir%\system32

SET FILE1=imageres.dll
SET FILE2=shell32.dll
SET FILE3=imagesp1.dll

SET FILE98=*.db
SET PATH98=%SYSTEMDRIVE%\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Explorer\
SET FILE99=IconCache.db
SET PATH99=%SYSTEMDRIVE%\Users\%USERNAME%\AppData\Local

TITLE Alumi Icon Pack 7600 X86 installer

:PERMISSIONCHK
	ATTRIB %windir%\system32 -h | FINDSTR /I "denied" >nul
	IF NOT ERRORLEVEL 1 (
		ECHO.
		ECHO.This script must be ran as an Administrator and with 
		ECHO.'User Account Control' completely disabled!!
		ECHO.
		GOTO END
	)

:CREATESYSTEMRESTOREPOINT
        ren %SOURCEFOLDER%Data\CreateRestore._vbs "CreateRestore.vbs"
        CLS
        ECHO.Creating a System Restore Point...
        cd\
        wscript.exe %SOURCEFOLDER%Data\CreateRestore.vbs
        ren %SOURCEFOLDER%Data\CreateRestore.vbs "CreateRestore._vbs"

:START
	IF /I EXIST %systemroot%\SysWOW64 SET BIT=Y

:DETECTARGUMENTS
	REM SET VAR1=1
	REM IF /I *%1 == *VAR SET VAR1=0

:TAKEOWNERSHIP
     IF '%BIT%'=='Y' (
        CLS.
	ECHO.THIS VERSION CANNOT BE RAN ON A 64 BIT SYSTEM!
        PAUSE
        GOTO JUSTEXIT
     ) ELSE (
        CLS
	ECHO.Taking ownership of %PATH1%\%FILE1%
	takeown /a /f %PATH1%\%FILE1%
	ECHO.Granting Admin rights
	ICACLS %PATH1%\%FILE1% /Grant Administrators:F
	
	ECHO.Taking ownership of %PATH1%\%FILE2%
	takeown /a /f %PATH1%\%FILE2%
	ECHO.Granting Admin rights
	ICACLS %PATH1%\%FILE2% /Grant Administrators:F
	
	ECHO.Taking ownership of %PATH1%\%FILE3%
	takeown /a /f %PATH1%\%FILE3%
	ECHO.Granting Admin rights
	ICACLS %PATH1%\%FILE3% /Grant Administrators:F

        REM - Try to set permissions for caches to hopefully enable deletion...
	ECHO Taking ownership of %PATH98%\%FILE98%
	takeown /a /f %PATH98%\%FILE98%
	ECHO Granting Admin rights
	ICACLS %PATH98%\%FILE98% /Grant Administrators:F

	ECHO.Taking ownership of %PATH99%\%FILE99%
	takeown /a /f %PATH99%\%FILE99%
	ECHO.Granting Admin rights
	ICACLS %PATH99%\%FILE99% /Grant Administrators:F
)

:SKIP64ONWERSHIP

:STOPPROTECTIONSERVICE
        CLS
        IF /I EXIST %PATH1%\%FILE1%.bak GOTO ALREADYPATCHED
	ECHO.Stopping Software Protection Services
	NET stop "Software Protection" /y

:BACKUPFILES
        CLS
        ECHO.Creating backups of original files...
	COPY "%PATH1%\%FILE1%" "%PATH1%\%FILE1%.bak"
	COPY "%PATH1%\%FILE2%" "%PATH1%\%FILE2%.bak"
	COPY "%PATH1%\%FILE3%" "%PATH1%\%FILE3%.bak"

:COPYFILES
        CLS
        cd\
        taskkill /f /IM explorer.exe
PAUSE
	REM - Copy the 32Bit files...
	ECHO.Copying "%SOURCEFOLDER%Data\System32\%FILE1%" to "%PATH1%\%FILE1%"
        ren "%PATH1%\%FILE1%" "imageres.TMP"
	COPY /Y "%SOURCEFOLDER%Data\System32\%FILE1%" "%PATH1%\%FILE1%"

	ECHO.Copying "%SOURCEFOLDER%Data\System32\%FILE2%" to "%PATH1%\%FILE2%"
        ren "%PATH1%\%FILE2%" "shell32.TMP"
	COPY /Y "%SOURCEFOLDER%Data\System32\%FILE2%" "%PATH1%\%FILE2%"

	ECHO.Copying "%SOURCEFOLDER%Data\System32\%FILE3%" to "%PATH1%\%FILE3%"
        ren "%PATH1%\%FILE3%" "imagesp1.TMP"
	COPY /Y "%SOURCEFOLDER%Data\System32\%FILE3%" "%PATH1%\%FILE3%"

        REM - Delete the IconCache.db and thumbnail caches...
        attrib -H "%PATH99%\%FILE99%"
	del "%PATH99%\%FILE99%"
        attrib -H "%PATH98%\%FILE98%"
	del "%PATH98%\%FILE98%"
 
REM - Add a reg key for RunOnce to run a cleanup script on restart...
REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v "AlumiIconPack7600X86" /t REG_EXPAND_SZ /d "%TEMP%\cleanins.cmd"

REM - Write a cmd file to the temp folder for use with the above RunOnce...
if exist "%TEMP%\cleanins.cmd" DEL %TEMP%\cleanins.cmd
>>%TEMP%.\cleanins.cmd ECHO.@ECHO OFF
>>%TEMP%.\cleanins.cmd ECHO.:CLEANUPSCRIPTBEGIN
>>%TEMP%.\cleanins.cmd ECHO.
>>%TEMP%.\cleanins.cmd ECHO.TITLE Alumi Icon Pack 7600 X86 Installer - Clean-Up...
>>%TEMP%.\cleanins.cmd ECHO.
>>%TEMP%.\cleanins.cmd ECHO.SET FILE98=*.db
>>%TEMP%.\cleanins.cmd ECHO.SET PATH98=%SYSTEMDRIVE%\Users\%USERNAME%\AppData\Local\Microsoft\Windows\Explorer\
>>%TEMP%.\cleanins.cmd ECHO.SET FILE99=IconCache.db
>>%TEMP%.\cleanins.cmd ECHO.SET PATH99=%%SYSTEMDRIVE%%\Users\%%USERNAME%%\AppData\Local
>>%TEMP%.\cleanins.cmd ECHO.
>>%TEMP%.\cleanins.cmd ECHO.:START
>>%TEMP%.\cleanins.cmd ECHO.	IF /I EXIST %%systemroot%%\SysWOW64 SET BIT=Y
>>%TEMP%.\cleanins.cmd ECHO.
>>%TEMP%.\cleanins.cmd ECHO.:CLEANTEMPFILES
>>%TEMP%.\cleanins.cmd ECHO.    attrib -H "%%PATH98%%\%%FILE98%%"
>>%TEMP%.\cleanins.cmd ECHO.	del "%%PATH98%%\%%FILE98%%"
>>%TEMP%.\cleanins.cmd ECHO.    attrib -H "%%PATH99%%\%%FILE99%%"
>>%TEMP%.\cleanins.cmd ECHO.	del "%%PATH99%%\%%FILE99%%"
>>%TEMP%.\cleanins.cmd ECHO.
>>%TEMP%.\cleanins.cmd ECHO.	del "%%WinDir%%\System32\imageres.TMP"
>>%TEMP%.\cleanins.cmd ECHO.	del "%%WinDir%%\System32\shell32.TMP"
>>%TEMP%.\cleanins.cmd ECHO.	del "%%WinDir%%\System32\imagesp1.TMP"
>>%TEMP%.\cleanins.cmd ECHO.
>>%TEMP%.\cleanins.cmd ECHO.:CLEANUPEND
>>%TEMP%.\cleanins.cmd ECHO.CLS
>>%TEMP%.\cleanins.cmd ECHO.ECHO.###########################################################
>>%TEMP%.\cleanins.cmd ECHO.ECHO.##         Alumi Icon Pack 7600 X86 Installer            ##
>>%TEMP%.\cleanins.cmd ECHO.ECHO.##     ---------------------------------------------     ##
>>%TEMP%.\cleanins.cmd ECHO.ECHO.##                                                       ##
>>%TEMP%.\cleanins.cmd ECHO.ECHO.##                Installation Complete!                 ##
>>%TEMP%.\cleanins.cmd ECHO.ECHO.##                                                       ##
>>%TEMP%.\cleanins.cmd ECHO.ECHO.##   You may now restart 'UAC' once explorer starts up!  ##
>>%TEMP%.\cleanins.cmd ECHO.ECHO.##                                                       ##
>>%TEMP%.\cleanins.cmd ECHO.ECHO.##               Thank you for installing!               ##
>>%TEMP%.\cleanins.cmd ECHO.ECHO.##                                                       ##
>>%TEMP%.\cleanins.cmd ECHO.ECHO.###########################################################
>>%TEMP%.\cleanins.cmd ECHO.ECHO.
>>%TEMP%.\cleanins.cmd ECHO.PAUSE
>>%TEMP%.\cleanins.cmd ECHO.

	REM - Add a RunOnce entry to registry to cleanup tmp files after restart...
	REGEDIT /S %TEMP%\cleanins.reg

	GOTO STARTPROTECTIONSERVICES

:ALREADYPATCHED
CLS
ECHO.
ECHO.
ECHO.###########################################################
ECHO.##                                                       ##
ECHO.##     Alumi Icon Pack 7600 X86 already installed.       ##
ECHO.## ----------------------------------------------------- ##
ECHO.##                                                       ##
ECHO.##   To uninstall, please look in the relevant folder!   ##
ECHO.##                                                       ##
ECHO.##                                                       ##
ECHO.##                        NOTICE:                        ##
ECHO.##     If you are trying to do a re-install, please      ##
ECHO.##           run the file in the 'Data' folder           ##
ECHO.##              called 'Delete_Backups.cmd'.             ##
ECHO.##                                                       ##
ECHO.##    Please refer to the 'README.txt' for more info.    ##
ECHO.##                                                       ##
ECHO.###########################################################
ECHO.
ECHO.
GOTO ALREADYPATCHEDEXIT

:STARTPROTECTIONSERVICES		
	ECHO.Starting Software Protection Services
	NET START "Software Protection"

:CONTINUE
CLS
ECHO.###########################################################
ECHO.##                                                       ##
ECHO.##                Installation Complete!                 ##
ECHO.##                                                       ##
ECHO.##          You MUST Restart Windows before ALL          ##
ECHO.##                changes can take place.                ##
ECHO.##                                                       ##
ECHO.## You can re-enable UAC ONCE the comptuer has restarted ##
ECHO.##                                                       ##
ECHO.##    You MUST also Restart Windows before attempting    ##
ECHO.##    to uninstall otherwise some file WILL be in use!   ##
ECHO.##                                                       ##
ECHO.###########################################################

:ASKAGAIN
ECHO.
ECHO.Restart Windows now?
ECHO.
ECHO.----------- 
ECHO.1. Yes.
ECHO.2. No.
ECHO.----------- 
set /p userinp2=Please choose a number(1-2):
set userinp2=%userinp2:~0,1%
if "%userinp2%"=="1" goto 1
if "%userinp2%"=="2" goto 2
ECHO.Invalid choice!
GOTO ASKAGAIN
:1
shutdown -r -t 01
:2

:END
EXPLORER.EXE
ECHO.It is now safe to close this window.
:ALREADYPATCHEDEXIT
PAUSE
:JUSTEXIT