def taskFile(config, file_info, uo_path): ''' This is the function that is called on thread creation. It is responsible for executing the downloading. verifying, and installation of files. Also it writes the updated hashes to the configuration file. ''' if file_info['DisplayName'] in config['Hashes']: local_f_md5 = config['Hashes'][file_info[ 'DisplayName']] # Get key from dictionary instead of computing. else: local_f_md5 = file_hash.grab_hash( uo_path + file_info['DisplayName']) # Compute the hash of the local file if local_f_md5 == True: # If the file doesn't exist.. dl_file = grab_file(file_info['URL']) # Download it, le_file = pull_file(dl_file) # Extract it. config['Hashes'][file_info['DisplayName']] = file_info['Hash'] file_parser.conf_write(config) for files in le_file: shutil_copy(files, uo_path + files) # Move it to the uo_directory. print(" [%s] Moved to the Ultima Directory." % files) elif local_f_md5: # If hash is computed. if file_hash.check_hash( local_f_md5, file_info['Hash']): # Check against the XML Hash config['Hashes'][file_info['DisplayName']] = file_info['Hash'] file_parser.conf_write(config) print(" [%s] Matching Hashes. Not installing." % file_info['DisplayName']) else: dl_file = grab_file(file_info['URL']) # Else, download the file le_file = pull_file(dl_file) # Extract the file. config['Hashes'][file_info['DisplayName']] = file_info['Hash'] file_parser.conf_write(config) for files in le_file: shutil_copy(files, uo_path + files) # Move the file to the new location. print(" [%s] Moved to the Ultima Directory." % files) else: print(" [%s] Bad file." % file_info['DisplayName'])
def taskFile(config, file_info, uo_path): ''' This is the function that is called on thread creation. It is responsible for executing the downloading. verifying, and installation of files. Also it writes the updated hashes to the configuration file. ''' if file_info['DisplayName'] in config['Hashes']: local_f_md5 = config['Hashes'][file_info['DisplayName']] # Get key from dictionary instead of computing. else: local_f_md5 = file_hash.grab_hash(uo_path + file_info['DisplayName']) # Compute the hash of the local file if local_f_md5 == True: # If the file doesn't exist.. dl_file = grab_file(file_info['URL']) # Download it, le_file = pull_file(dl_file) # Extract it. config['Hashes'][file_info['DisplayName']] = file_info['Hash'] file_parser.conf_write(config) for files in le_file: shutil_copy(files, uo_path + files) # Move it to the uo_directory. print(" [%s] Moved to the Ultima Directory." % files) elif local_f_md5: # If hash is computed. if file_hash.check_hash(local_f_md5, file_info['Hash']): # Check against the XML Hash config['Hashes'][file_info['DisplayName']] = file_info['Hash'] file_parser.conf_write(config) print(" [%s] Matching Hashes. Not installing." % file_info['DisplayName']) else: dl_file = grab_file(file_info['URL']) # Else, download the file le_file = pull_file(dl_file) # Extract the file. config['Hashes'][file_info['DisplayName']] = file_info['Hash'] file_parser.conf_write(config) for files in le_file: shutil_copy(files, uo_path + files) # Move the file to the new location. print(" [%s] Moved to the Ultima Directory." % files) else: print(" [%s] Bad file." % file_info['DisplayName'])
update_xml = "http://www.ultima-shards.com/patches/UOP/Updates.xml" # Else, use a pre-defined. if not config['Files']['uo_directory']: dir_list = file_process.getUOPath() # Just ya. Full path. uo_path = "" # Null out uo_path for directory in dir_list: if not os.path.exists( directory ): # Verify that the UO path does indeed exist.. otherwise exit. pass else: print("Updating \"config.ini\" with discovered Ultima directory:") config['Files'][ 'uo_directory'] = directory # Use the uo_directory in configuration file_parser.conf_write(config) # Write changes to config file. print(" Ultima Directory:\n %s\n" % directory) # Pretty, pretty display of directory. uo_path = directory # Set the path else: uo_path = config['Files'][ 'uo_directory'] # Use the path in configuration file. print(" Ultima Directory:\n %s\n" % uo_path) if not uo_path: print("Directory not found for Ultima Online.") print( "You need to add your path to the configuration file called: \"config.ini\"" ) if os.name == "nt": input(" Press any key to exit...") # A pause for windows users.
if 'xml_url' in config['Files']: # If xml is defined in configuration file.. update_xml = config['Files']['xml_url'] # use that one. else: update_xml = "http://www.ultima-shards.com/patches/UOP/Updates.xml" # Else, use a pre-defined. if not config['Files']['uo_directory']: dir_list = file_process.getUOPath() # Just ya. Full path. uo_path = "" # Null out uo_path for directory in dir_list: if not os.path.exists(directory): # Verify that the UO path does indeed exist.. otherwise exit. pass else: print("Updating \"config.ini\" with discovered Ultima directory:") config['Files']['uo_directory'] = directory # Use the uo_directory in configuration file_parser.conf_write(config) # Write changes to config file. print(" Ultima Directory:\n %s\n" % directory) # Pretty, pretty display of directory. uo_path = directory # Set the path else: uo_path = config['Files']['uo_directory'] # Use the path in configuration file. print(" Ultima Directory:\n %s\n" % uo_path) if not uo_path: print("Directory not found for Ultima Online.") print("You need to add your path to the configuration file called: \"config.ini\"") if os.name == "nt": input(" Press any key to exit...") # A pause for windows users. exit() # Pull the Update(s).xml #