diff --git a/webui/src/main/java/com/muwire/webui/ConfigurationServlet.java b/webui/src/main/java/com/muwire/webui/ConfigurationServlet.java index 421c44de..9ae7c608 100644 --- a/webui/src/main/java/com/muwire/webui/ConfigurationServlet.java +++ b/webui/src/main/java/com/muwire/webui/ConfigurationServlet.java @@ -93,11 +93,11 @@ public class ConfigurationServlet extends HttpServlet { private static File getDirectory(String s) throws Exception { File f = new File(s); if (!f.exists()) - throw new Exception(Util._t("Bad input")+ Util._t("{0} does not exist",s)); + throw new Exception(Util._t("Bad input") + ":" + Util._t("{0} does not exist",s)); if (!f.isDirectory()) - throw new Exception(Util._t("Bad input")+ Util._t("{0} is not a directory",s)); + throw new Exception(Util._t("Bad input") + ":" + Util._t("{0} is not a directory",s)); if (!f.canWrite()) - throw new Exception(Util._t("Bad input")+ Util._t("{0} not writeable",s)); + throw new Exception(Util._t("Bad input") + ":" + Util._t("{0} not writeable",s)); return f; } diff --git a/webui/src/main/java/com/muwire/webui/InitServlet.java b/webui/src/main/java/com/muwire/webui/InitServlet.java new file mode 100644 index 00000000..6b079981 --- /dev/null +++ b/webui/src/main/java/com/muwire/webui/InitServlet.java @@ -0,0 +1,55 @@ +package com.muwire.webui; + +import java.io.File; +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class InitServlet extends HttpServlet { + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + try { + String nickname = req.getParameter("nickname"); + if (nickname == null || nickname.trim().length() == 0) + throw new Exception("Nickname cannot be blank"); + + String downloadLocation = req.getParameter("download_location"); + if (downloadLocation == null) + throw new Exception("Download location cannot be blank"); + File downloadLocationFile = new File(downloadLocation); + if (!downloadLocationFile.exists()) { + if (!downloadLocationFile.mkdirs()) + throw new Exception("Couldn't create download location"); + } else if (downloadLocationFile.isFile()) + throw new Exception("Download location must point to a directory"); + else if (!downloadLocationFile.canWrite()) + throw new Exception("Download location not writeable"); + + String incompleteLocation = req.getParameter("incomplete_location"); + if (incompleteLocation == null) + throw new Exception("Incomplete files location cannot be blank"); + File incompleteLocationFile = new File(incompleteLocation); + if (!incompleteLocationFile.exists()) { + if (!incompleteLocationFile.mkdirs()) + throw new Exception("Couldn't create incomplete files location"); + } else if (incompleteLocationFile.isFile()) + throw new Exception("Incomplete files location must point to a directory"); + else if (!incompleteLocationFile.canWrite()) + throw new Exception("Incomplete files location not writeable"); + + MuWireClient client = (MuWireClient) req.getServletContext().getAttribute("mwClient"); + client.initMWProps(nickname, downloadLocationFile, incompleteLocationFile); + client.start(); + resp.sendRedirect("/MuWire/index"); + } catch (Throwable e) { + req.getServletContext().setAttribute("MWInitError", e); + resp.sendRedirect("/MuWire/MuWire"); + } + + } + +} diff --git a/webui/src/main/java/com/muwire/webui/Util.java b/webui/src/main/java/com/muwire/webui/Util.java index d041d82b..114c6adc 100644 --- a/webui/src/main/java/com/muwire/webui/Util.java +++ b/webui/src/main/java/com/muwire/webui/Util.java @@ -44,6 +44,7 @@ public class Util { _x("Download"), _x("Download Location"), _x("Download retry frequency (seconds)"), + _x("Download speed smoothing interval (second)"), _x("Downloader"), _x("Downloading"), _x("Enter Reason (Optional)"), diff --git a/webui/src/main/webapp/MuWire.jsp b/webui/src/main/webapp/MuWire.jsp index 7d85f026..766d0823 100644 --- a/webui/src/main/webapp/MuWire.jsp +++ b/webui/src/main/webapp/MuWire.jsp @@ -15,6 +15,8 @@ String defaultIncompletesLocation = System.getProperty("user.home") + File.separator+"MuWire Incompletes"; session.setAttribute("defaultDownloadLocation",defaultDownloadLocation); session.setAttribute("defaultIncompletesLocation",defaultIncompletesLocation); + + Throwable error = (Throwable) application.getAttribute("MWInitError"); %> + +<% if (error != null) { %> +
<%=Util._t("Welcome to MuWire! Please select a nickname and download locations")%>