Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashes and on Windows with files across multiple drives/paths #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

import os
import os.path
import sys
import time
import threading
Expand Down Expand Up @@ -835,26 +836,26 @@ def goProgram(self,filename):

if self.currentBoard=="microbit":
if str(filename).find("./")>=0:
aline="exec(open('%s').read(),globals())"%str(filename[2:])
aline="exec(open('%s').read(),globals())"%str(os.path.split(filename)[1])
else:
aline="exec(open('%s').read(),globals())"%str(filename)
aline="exec(open('%s').read(),globals())"%str(os.path.split(filename)[1])
for i in aline:
self.ctrltouartQueue.put("uitouart:::%s"%i)
time.sleep(0.001)
self.ctrltouartQueue.put("exec_:::\r")
else:
self.ctrltouartQueue.put("exec_:::exec(open(\'%s\').read(),globals())\r\n"%str(filename))
self.ctrltouartQueue.put("exec_:::exec(open(\'%s\').read(),globals())\r\n"%str(os.path.split(filename)[1]))

def loadFile(self,filename):
self.loadFileBool=True
self.loadFileMsg=""
if self.currentBoard=="microbit":
aline="print(open('%s','r').read())\r"%str(filename[2:])
aline="print(open('%s','r').read())\r"%str(os.path.split(filename)[1])
for i in aline:
self.ctrltouartQueue.put("ctrltouart:::%s"%i)
time.sleep(0.001)
else:
self.ctrltouartQueue.put("ctrltouart:::print(open(\'%s\',\'rU\').read())\r\n"%str(filename))
self.ctrltouartQueue.put("ctrltouart:::print(open(\'%s\',\'rU\').read())\r\n"%str(os.path.split(filename)[1]))

startTime=time.time()
while 1:
Expand Down Expand Up @@ -954,7 +955,7 @@ def downloadFile(self,filename):
return
afile=self.dropDownFileName
#elif filename.find(":")<0:
elif filename.find(rootDirectoryPath)<0:
elif filename.find(rootDirectoryPath)<0 and os.path.isabs(filename) == False:
fileHandle=open(currentTempPath+filename,'rbU')
else:
myfile=open(currentTempPath+"/"+str(filename.split("/")[-1]),"w",encoding='UTF-8')
Expand Down Expand Up @@ -998,7 +999,7 @@ def downloadFile(self,filename):
self.ctrltouartQueue.put("ctrltouart:::%s"%i)
time.sleep(0.001)
else:
self.ctrltouartQueue.put("ctrltouart:::myfile=open(\'%s\',\'w\')\r\n"%str(afile))
self.ctrltouartQueue.put("ctrltouart:::myfile=open(\'%s\',\'w\')\r\n"%str(os.path.split(afile)[1]))

startTime=time.time()
while 1:
Expand Down
3 changes: 2 additions & 1 deletion uPyCraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import math
import json
import os
import os.path
import Esp
import shutil
import webbrowser
Expand Down Expand Up @@ -1472,7 +1473,7 @@ def slotDownloadFile(self):
return False

#if str(self.fileName).find(":")>=0:
if str(self.fileName).find(rootDirectoryPath)>=0:
if os.path.isabs(self.fileName):
afile=self.fileName
else:
afile=self.fileName
Expand Down