[D
	/LoadSW [P
		[A LoadFlag ]	% LoadFlag = False -> Check only if Files are existing
		
		/Result #1 def
		/MissingFile '' def
		
		% Build SW File name
		/SWFile FilePath MCDir add '\' add MCSWFileName add def
		/SWFile SWFile 'S' add EloSWVersion 16 cvrs add def
		/SWFile SWFile '_V' add MCSWVersion cvs add 'S' add MCSWSubVersion cvs add def 
		MCSWBetaInfo '' ne [B
			/SWFile SWFile '_' add MCSWBetaInfo add def
		] if
		/SWFile SWFile '.HX3' add def
		
		% Build Tree File name
		/TreeFile FilePath MCDir add '\' add MCTreeFileName add def
		/TreeFile TreeFile 'S' add EloSWVersion 16 cvrs add def
		/TreeFile TreeFile PowerExtension add IntfMCTreeExt add def
		/TreeFile TreeFile '_V' add MCTreeVersion cvs add 'S' add MCTreeSubVersion cvs add def 
		MCTreeBetaInfo '' ne [B
			/TreeFile TreeFile '_' add MCTreeBetaInfo add def
		] if
		/TreeFile TreeFile '.HX2' add def
		
		% Build DefaultPar File name
		/DefaultParFile FilePath MCDir add '\' add MCTreeFileName add def
		/DefaultParFile DefaultParFile 'S' add EloSWVersion 16 cvrs add def
		/DefaultParFile DefaultParFile PowerExtension add IntfMCTreeExt add def
		/DefaultParFile DefaultParFile '_V' add MCTreeVersion cvs add 'S' add MCTreeSubVersion cvs add def 
		MCTreeBetaInfo '' ne [B
			/DefaultParFile DefaultParFile '_' add MCTreeBetaInfo add def
		] if
		/DefaultParFile DefaultParFile '.GR3' add def
		
		
		% check if files are existing
		Result [B
			SWFile FileExist not [B
				/Result #0 def 
				/MissingFile SWFile def
			] if
		] if
		Result [B
			TreeFile FileExist not [B
				/Result #0 def 
				/MissingFile TreeFile def
			] if
		] if
		Result [B
			DefaultParFile FileExist not [B
				/Result #0 def 
				/MissingFile DefaultParFile def
			] if
		] if
		
		
		Result LoadFlag and [B
			% Read drive
			% Get Installation Valid Flag
			/InstVal MCInstallValidAddr PackInst:ReadMemory def
			
			% Get SW CRC
			/CRC_drive_SW MC_SW_CRC_Addr PackInst:_GetBlock def
			
			% Get Tree CRC
			/CRC_drive_Tr MC_Tr_CRC_Addr PackInst:_GetBlock def
			
			% Get SW file name
			/Filename_read_SW MC_SW_FileName_Addr GetInstalledFileName uppercase def
			
			% Get Tree file name
			/Filename_read_Tr MC_Tr_FileName_Addr GetInstalledFileName uppercase def
			
			
			% Read file
			% Get SW CRC
			getcurrentdir '\' add SWFile add MC_SW_CRC_Addr SystGen_CRC crcfromfile
			/Res exch def
			/CRC_file_SW exch def
			
			% Get Tree CRC
			getcurrentdir '\' add TreeFile add MC_Tr_CRC_Addr SystGen_CRC crcfromfile
			/Res exch def
			/CRC_file_Tr exch def
			
			% Get SW file name
			/Filename_file_SW SWFile extfilename '' chfileext uppercase def
			
			% Get Tree file name
			/Filename_file_Tr TreeFile extfilename '' chfileext uppercase def
			
			% Check CRC
			CRC_file_SW CRC_invalid1 eq
			CRC_file_SW CRC_invalid2 eq or [B
				'File: ' SWFile extfilename add ' is corrupted!' add log
				/Result #0 def
			] if
			
			CRC_file_Tr CRC_invalid1 eq
			CRC_file_Tr CRC_invalid2 eq or [B
				'File: ' TreeFile extfilename add ' is corrupted!' add log
				/Result #0 def
			] if
			
			
			Result [B
				InstVal InstallationValid ne [B
					'Erasing MC SW firmware sector...' log
					'Erasing MC Tree firmware sector...' log
					1 EraseSWInstance
					
					'Downloading ' SWFile add log
					SWFile dup loadobj exch PackInst:DownloadHX3File
					
					'Downloading ' TreeFile add log
					TreeFile dup loadobj exch PackInst:DownloadHX2File
					
					'Updating UPID list...' log
					TalkIntf.UpdateUPIDList
					TalkIntf.GetResult 0 ne [B
						ResetDevice
						10000 wait
					] if
				][B
					/InstallSW
						Filename_file_SW Filename_read_SW ne
						CRC_file_SW CRC_drive_SW ne or def
					
					/InstallTr
						Filename_file_Tr Filename_read_Tr ne
						CRC_file_Tr CRC_drive_Tr ne or def
					
					InstallSW [B
						MCInstallValidAddr InstallationInvalid WriteWordToElo
					
						'Erasing MC SW firmware sector...' log
						11 EraseSWInstance
						
						'Downloading ' SWFile add log
						SWFile dup loadobj exch PackInst:DownloadHX3File
					][B
						'Download MC SW firmware skipped. Already up to date...' log
					] ifelse
					
					InstallTr [B
						MCInstallValidAddr InstallationInvalid WriteWordToElo
					
						'Erasing MC Tree firmware sector...' log
						101 EraseSWInstance
						
						'Downloading ' TreeFile add log
						TreeFile dup loadobj exch PackInst:DownloadHX2File
						
						'Updating UPID list...' log
						TalkIntf.UpdateUPIDList
						TalkIntf.GetResult 0 ne [B
							ResetDevice
							10000 wait
						] if
					][B
						'Download MC Tree firmware skipped. Already up to date...' log
					] ifelse
				] ifelse
			] if
		] if
		
		[A /MissingFile /Result]
	]
]
