Only add directory entry on paste if directory does not exist, fix servefiles on Python 3.

This commit is contained in:
Steveice10 2017-06-06 11:30:37 -07:00
parent ddb18e3058
commit f7ac0c4020
2 changed files with 24 additions and 29 deletions

View File

@ -12,13 +12,12 @@ import urllib
try: try:
from SimpleHTTPServer import SimpleHTTPRequestHandler from SimpleHTTPServer import SimpleHTTPRequestHandler
from SocketServer import TCPServer from SocketServer import TCPServer
from urlparse import urljoin from urllib import quote
from urllib import pathname2url, quote input = raw_input
except ImportError: except ImportError:
from http.server import SimpleHTTPRequestHandler from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer from socketserver import TCPServer
from urllib.parse import urljoin, quote from urllib.parse import quote
from urllib.request import pathname2url
interactive = False interactive = False
@ -39,15 +38,15 @@ accepted_extension = ('.cia', '.tik', '.cetk')
hostPort = 8080 # Default value hostPort = 8080 # Default value
if interactive: if interactive:
target_ip = raw_input("The IP of your 3DS: ") target_ip = input("The IP of your 3DS: ")
target_path = raw_input("The file you want to send (.cia, .tik, or .cetk): ") target_path = input("The file you want to send (.cia, .tik, or .cetk): ")
hostIp = raw_input("Host IP (or press Enter to have the script detect host IP):") hostIp = input("Host IP (or press Enter to have the script detect host IP):")
if hostIp == '': if hostIp == '':
print('Detecting host IP...') print('Detecting host IP...')
hostIp = [(s.connect(('8.8.8.8', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1] hostIp = [(s.connect(('8.8.8.8', 53)), s.getsockname()[0], s.close()) for s in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1]
else: else:
hostPort = raw_input("Host port (or press Enter to keep default, 8080):") hostPort = input("Host port (or press Enter to keep default, 8080):")
if hostPort == '': if hostPort == '':
hostPort = 8080 # Default hostPort = 8080 # Default

View File

@ -78,16 +78,7 @@ static Result action_paste_contents_make_dst_directory(void* data, u32 index) {
Handle dirHandle = 0; Handle dirHandle = 0;
if(R_SUCCEEDED(FSUSER_OpenDirectory(&dirHandle, pasteData->target->archive, *fsPath))) { if(R_SUCCEEDED(FSUSER_OpenDirectory(&dirHandle, pasteData->target->archive, *fsPath))) {
FSDIR_Close(dirHandle); FSDIR_Close(dirHandle);
} else { } else if(R_SUCCEEDED(res = FSUSER_CreateDirectory(pasteData->target->archive, *fsPath, attributes))) {
res = FSUSER_CreateDirectory(pasteData->target->archive, *fsPath, attributes);
}
util_free_path_utf8(fsPath);
} else {
res = R_FBI_OUT_OF_MEMORY;
}
if(R_SUCCEEDED(res)) {
char parentPath[FILE_PATH_MAX]; char parentPath[FILE_PATH_MAX];
util_get_parent_path(parentPath, dstPath, FILE_PATH_MAX); util_get_parent_path(parentPath, dstPath, FILE_PATH_MAX);
@ -106,6 +97,11 @@ static Result action_paste_contents_make_dst_directory(void* data, u32 index) {
} }
} }
util_free_path_utf8(fsPath);
} else {
res = R_FBI_OUT_OF_MEMORY;
}
return res; return res;
} }