Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.
Closed
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
10 changes: 9 additions & 1 deletion src/main/scala/org/codeoverflow/chatoverflow/ChatOverflow.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.codeoverflow.chatoverflow
import java.security.Policy

import org.codeoverflow.chatoverflow.api.APIVersion
import org.codeoverflow.chatoverflow.configuration.{ConfigurationService, CredentialsService}
import org.codeoverflow.chatoverflow.configuration.{ConfigurationFolder, ConfigurationService, CredentialsService}
import org.codeoverflow.chatoverflow.connector.ConnectorRegistry
import org.codeoverflow.chatoverflow.framework.PluginFramework
import org.codeoverflow.chatoverflow.framework.security.SandboxSecurityPolicy
Expand All @@ -28,6 +28,7 @@ class ChatOverflow(val pluginFolderPath: String,
val typeRegistry = new TypeRegistry(requirementPackage)
val credentialsService = new CredentialsService(s"$configFolderPath/credentials")
val configService = new ConfigurationService(s"$configFolderPath/config.xml")
val configFolder = new ConfigurationFolder(s"$configFolderPath/")

/**
* Initializes all parts of chat overflow. These can be accessed trough the public variables.
Expand All @@ -53,13 +54,20 @@ class ChatOverflow(val pluginFolderPath: String,
logger debug "Finished updating type registry."

logger debug "Loading configs and credentials."
createConfigFolder()
askForPassword()
load()
logger debug "Finished loading configs and credentials."

logger debug "Finished initialization."
}

private def createConfigFolder(): Unit = {
if (!configFolder.doesExists()) {
configFolder.createFolder()
}
}

private def askForPassword(): Unit = {
val password = scala.io.StdIn.readLine("Please enter password > ").toCharArray
credentialsService.setPassword(password)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.codeoverflow.chatoverflow.configuration

import java.io.File

import org.codeoverflow.chatoverflow.WithLogger

/**
* The configuration folder provides a method to create a configuration folder.
*
* @param configFilePath the file path of the configuration folder
*/
class ConfigurationFolder(val configFilePath: String) extends WithLogger {

val file = new File(configFilePath)

/**
* Creates the Folder
*
* @return true, if the folder was created correctly.
*/
def createFolder(): Boolean = {
logger debug s"Config Folder $configFilePath not found. Creating Folder."
try {
file.mkdir()
logger debug s"Created Folder $configFilePath."
true
} catch {
case e: Exception =>
logger warn s"Unable to create Folder. An error occurred: ${e.getMessage}"
false
}
}

/**
* Checks if the folder already exists
*
* @return true, if the folder already exists.
*/
def doesExists(): Boolean = {
file.exists()
}

}