Skip to content

Commit

Permalink
Merge pull request #38 from BDisp/file-not-found-darwin-fix
Browse files Browse the repository at this point in the history
Fixes #37. File not found - darwin*.*.
  • Loading branch information
BDisp authored Nov 11, 2024
2 parents 8bccda8 + 913f682 commit db0ed99
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 63 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ dist/
*.spec
*.pyc
/.vs
/.vscode
Binary file modified dumpsmc.exe
Binary file not shown.
Binary file modified gettools.exe
Binary file not shown.
160 changes: 100 additions & 60 deletions gettools.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,20 @@
import tarfile
import zipfile
import time
import urllib

try:
# For Python 3.0 and later
import urllib
# noinspection PyCompatibility
from urllib.request import urlopen
from urllib.request import urlopen, Request, urlretrieve, install_opener
# noinspection PyCompatibility
from html.parser import HTMLParser
# noinspection PyCompatibility
from urllib.request import urlretrieve
# noinspection PyCompatibility
from urllib.request import install_opener
except ImportError:
# Fall back to Python 2
# noinspection PyCompatibility
from urllib2 import urlopen
import urllib2
# noinspection PyCompatibility
from urllib2 import urlopen, Request
# noinspection PyCompatibility
from HTMLParser import HTMLParser

Expand Down Expand Up @@ -120,49 +118,39 @@ def CheckToolsFilesExists(dest):
def GetResponseFromUrl(url):
try:
# Try to read page
if sys.version_info > (3, 0):
# Python 3 code in this block
req = urllib.request.Request(url, headers={'User-Agent' : "Magic Browser"})
response = urllib.request.urlopen( req )
return response
else:
# Python 2 code in this block
req = urllib.Request(url, headers={'User-Agent' : "Magic Browser"})
response = urllib.urlopen( req )
return response
# Add a User-Agent header to the request
req = Request(url, headers={'User-Agent' : "Magic Browser"})
response = urlopen( req )
return response
except:
print('Couldn\'t read page')
return False

def main():
# Check minimal Python version is 2.7
if sys.version_info < (2, 7):
sys.stderr.write('You need Python 2.7 or later\n')
sys.exit(1)

dest = os.getcwd()

# Try local file check
if(CheckToolsFilesExists(dest)):
# User as already download the tools and chosen not doing again
return

# Re-create the tools folder
shutil.rmtree(dest + '/tools', True)
# Function to download a file
def DownloadFile(url, filename):
try:
os.mkdir(dest + '/tools')
except :
pass
# Add a User-Agent header to the request
request = Request(url, headers={'User-Agent': 'Magic Browser'})
response = urlopen(request)
# Save the content to a file
with open(filename, 'wb') as file:
file.write(response.read())

print(f"Downloaded {filename}")
except Exception as e:
print(f"Error downloading {filename}: {e}")
return False

# Function to download and extract tar file
def DownloadAndExtractTarFile(url, dest):
parser = CDSParser()

print('Trying to get tools from ' + url)

# Last published version doesn't ship with darwin tools
# so in case of error get it from the core.vmware.fusion.tar
print('Trying to get tools from the packages folder...')

# Setup secure url and file paths
url = 'https://softwareupdate.vmware.com/cds/vmw-desktop/fusion/'

# Get the list of Fusion releases
# And get the last item in the ul/li tags
response = GetResponseFromUrl(url)
Expand All @@ -181,9 +169,9 @@ def main():
return
html = response.read()
parser.feed(str(html))

lastVersion = parser.HTMLDATA[-1]

fromLocal = '/universal/core/'
zipName = 'com.vmware.fusion.zip'
tarName = zipName + '.tar'
Expand All @@ -206,17 +194,17 @@ def main():
opener.Version = [('User-Agent','Magic Browser')]
(f,headers)=opener.retrieve(urlpost15, convertpath(dest + '/tools/' + tarName), reporthook)
except:
print('Couldn\'t find tools')
return
print('Couldn\'t find tools in ' + url)
return False

print()

# Extract the tar to zip
print('Extracting ' + tarName + '...')
tar = tarfile.open(convertpath(dest + '/tools/' + tarName), 'r')
tar.extract(zipName, path=convertpath(dest + '/tools/'))
tar.close()

# Extract files from zip
print('Extracting files from ' + zipName + '...')
cdszip = zipfile.ZipFile(convertpath(dest + '/tools/' + zipName), 'r')
Expand All @@ -226,21 +214,73 @@ def main():
if not (isoPath in cdszip.namelist()):
isoPath = 'payload/VMware Fusion.app/Contents/Library/isoimages/'

# Extract the iso files from zip
cdszip.extract(isoPath + 'darwin.iso', path=convertpath(dest + '/tools/'))
cdszip.extract(isoPath + 'darwinPre15.iso', path=convertpath(dest + '/tools/'))
cdszip.close()

# Move the iso files to tools folder
shutil.move(convertpath(dest + '/tools/' + isoPath + 'darwin.iso'), convertpath(dest + '/tools/darwin.iso'))
shutil.move(convertpath(dest + '/tools/' + isoPath + 'darwinPre15.iso'), convertpath(dest + '/tools/darwinPre15.iso'))

# Cleanup working files and folders
shutil.rmtree(convertpath(dest + '/tools/payload'), True)
os.remove(convertpath(dest + '/tools/' + tarName))
os.remove(convertpath(dest + '/tools/' + zipName))

print('Tools from core retrieved successfully')
try:
# Extract the iso files from zip
cdszip.extract(isoPath + 'darwin.iso', path=convertpath(dest + '/tools/'))
cdszip.extract(isoPath + 'darwinPre15.iso', path=convertpath(dest + '/tools/'))
cdszip.close()

# Move the iso files to tools folder
shutil.move(convertpath(dest + '/tools/' + isoPath + 'darwin.iso'), convertpath(dest + '/tools/darwin.iso'))
shutil.move(convertpath(dest + '/tools/' + isoPath + 'darwinPre15.iso'), convertpath(dest + '/tools/darwinPre15.iso'))

print('Tools from core retrieved successfully')
except:
print('Couldn\'t find tools in ' + isoPath)
cdszip.close()
return False
finally:
# Cleanup working files and folders
shutil.rmtree(convertpath(dest + '/tools/payload'), True)
os.remove(convertpath(dest + '/tools/' + tarName))
os.remove(convertpath(dest + '/tools/' + zipName))

def main():
# Check minimal Python version is 2.7
if sys.version_info < (2, 7):
sys.stderr.write('You need Python 2.7 or later\n')
sys.exit(1)

dest = os.getcwd()

# Try local file check
if(CheckToolsFilesExists(dest)):
# User as already download the tools and chosen not doing again
return

# Re-create the tools folder
shutil.rmtree(dest + '/tools', True)
try:
os.mkdir(dest + '/tools')
except :
pass

# Setup secure url and file paths
url = 'https://softwareupdate.vmware.com/cds/vmw-desktop/fusion/'

response = DownloadAndExtractTarFile(url, dest)
if response == False or response == None:
base_url = "https://packages-prod.broadcom.com/tools/frozen/darwin/"
# base_url = "https://packages.vmware.com/tools/frozen/darwin/"
iso_files = ["darwin.iso", "darwinPre15.iso"]
print('Trying to get tools from ' + base_url)

# Download the darwin.iso and darwinPre15.iso files
for iso in iso_files:
file_url = base_url + iso
response = DownloadFile(file_url, iso)
if response == False:
return

# Move the ISO files to the tools folder
shutil.move(convertpath(dest + '/' + iso_files[0]), convertpath(dest + '/tools/' + iso_files[0]))
shutil.move(convertpath(dest + '/' + iso_files[1]), convertpath(dest + '/tools/' + iso_files[1]))
print('Move the ISO files to the tools folder')

print()

print('Tools from frozen retrieved successfully')

return

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion lnx-install.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash

set -e

echo "Unlocker 3.0.4 for VMware Workstation"
Expand Down Expand Up @@ -44,4 +45,3 @@ $pyversion gettools.py
cp ./tools/darwin*.* /usr/lib/vmware/isoimages/

echo Finished!

2 changes: 1 addition & 1 deletion lnx-update-tools.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash

set -e

echo "Get macOS VMware Tools 3.0.4"
Expand Down Expand Up @@ -29,4 +30,3 @@ $pyversion gettools.py
cp ./tools/darwin*.* /usr/lib/vmware/isoimages/

echo Finished!

Binary file modified unlocker.exe
Binary file not shown.
4 changes: 3 additions & 1 deletion win-update-tools.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ echo VMware is installed at: %InstallPath%

echo Getting VMware Tools...
gettools.exe
xcopy /F /Y .\tools\darwin*.* "%InstallPath%"
if NOT "%InstallPath%" == "" (
xcopy /F /Y .\tools\darwin*.* "%InstallPath%"
)

popd

Expand Down

0 comments on commit db0ed99

Please sign in to comment.