Skip to content

Commit 49cf29e

Browse files
committed
ANDROID: file manager webui (wip)
1 parent 6f4333c commit 49cf29e

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/MainActivity.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,11 @@ private void processIntent() {
865865
}
866866

867867
private void processSettings() {
868+
FileInputStream is = null;
868869
try {
870+
is = getApplication().openFileInput("settings.txt");
869871
Properties p = new Properties();
870-
p.load(getApplication().openFileInput("settings.txt"));
872+
p.load(is);
871873
int socket = Integer.parseInt(p.getProperty("serverSocket", "-1"));
872874
String token = p.getProperty("serverToken", new Date().toString());
873875
if (socket > 1023 && socket < 65536) {
@@ -878,6 +880,15 @@ private void processSettings() {
878880
}
879881
} catch (Exception e) {
880882
Log.i(TAG, "Failed to start web service: ", e);
883+
} finally {
884+
if (is != null) {
885+
try {
886+
is.close();
887+
}
888+
catch (IOException e) {
889+
Log.i(TAG, "Failed to close settings.txt: ", e);
890+
}
891+
}
881892
}
882893
}
883894

src/platform/android/app/src/main/java/net/sourceforge/smallbasic/WebServer.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public void run(final int socketNum, final String token) {
5151
public void run() {
5252
try {
5353
runServer(socketNum, token);
54-
} catch (IOException e) {
55-
log("startServer failed: ", e);
54+
} catch (Exception e) {
55+
log("Server failed to start: ", e);
5656
}
5757
}
5858
});
@@ -87,6 +87,7 @@ private void runServer(final int socketNum, final String token) throws IOExcepti
8787
THREAD_POOL.submit(new Request(socket, token));
8888
} catch (Exception e) {
8989
log("Server failed", e);
90+
break;
9091
}
9192
}
9293
}
@@ -321,15 +322,15 @@ public void run() {
321322
}
322323
}
323324
} catch (IOException e) {
324-
log("request failed", e);
325+
log("Request failed", e);
325326
}
326327
finally {
327328
afterRun();
328329
}
329330
}
330331

331332
private void afterRun() {
332-
log("socket cleanup");
333+
log("Socket cleanup");
333334
try {
334335
if (socket != null) {
335336
socket.close();
@@ -338,7 +339,7 @@ private void afterRun() {
338339
inputStream.close();
339340
}
340341
} catch (IOException e) {
341-
log("socket cleanup failed: ", e);
342+
log("Socket cleanup failed: ", e);
342343
}
343344
}
344345

@@ -389,7 +390,7 @@ private Response handleDownload(Map<String, Collection<String>> data) throws IOE
389390
* Handler for files API
390391
*/
391392
private Response handleFileList() throws IOException {
392-
log("sending file list");
393+
log("Sending file list");
393394
JsonBuilder builder = new JsonBuilder();
394395
builder.append('[');
395396
long id = 0;
@@ -433,7 +434,7 @@ private void handlePost(Map<String, String> data) throws IOException {
433434
if (userToken == null) {
434435
userToken = requestToken;
435436
}
436-
log("userToken=" + userToken);
437+
log("UserToken=" + userToken);
437438
if (tokenKey.equals(userToken)) {
438439
if (url.startsWith("/api/login")) {
439440
handleFileList().send(socket, userToken);
@@ -532,7 +533,7 @@ private Response handleWebResponse(String asset) throws IOException {
532533
try {
533534
result = getFile(path, true);
534535
} catch (Exception e) {
535-
log("error: " + e);
536+
log("Error: " + e);
536537
result = null;
537538
}
538539
return result != null ? result : new Response(SC_NOT_FOUND);
@@ -570,7 +571,7 @@ public Response(int errorCode) throws IOException {
570571
* Sends the response to the given socket
571572
*/
572573
void send(Socket socket, String cookie) throws IOException {
573-
log("sendResponse() entered");
574+
log("Sending response");
574575
String contentLength = "Content-length: " + length + "\r\n";
575576
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());
576577
String code = errorCode == SC_OKAY ? SC_OKAY + " OK" : String.valueOf(errorCode);
@@ -583,7 +584,7 @@ void send(Socket socket, String cookie) throws IOException {
583584
out.write("Server: SmallBASIC for Android\r\n\r\n".getBytes(UTF_8));
584585
socket.setSendBufferSize(SEND_SIZE);
585586
int sent = toStream(out);
586-
log("sent " + sent + " bytes");
587+
log("Sent " + sent + " bytes");
587588
out.close();
588589
}
589590

0 commit comments

Comments
 (0)