-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from amank22/spx_db_location
Db location from user home
- Loading branch information
Showing
13 changed files
with
177 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package storage | ||
|
||
import com.voxfinite.logvue.APP_NAME | ||
import net.harawata.appdirs.AppDirsFactory | ||
import org.mapdb.DB | ||
import org.mapdb.DBException | ||
import org.mapdb.DBMaker | ||
import utils.DbCreationException | ||
import utils.reportException | ||
import java.io.File | ||
import java.io.IOException | ||
import java.nio.file.FileSystems | ||
import java.nio.file.Files | ||
import java.nio.file.attribute.PosixFilePermissions | ||
|
||
|
||
object StorageHelper { | ||
|
||
internal fun createDiskDb(): DB { | ||
val dbFile = getDbFile() | ||
return try { | ||
DBMaker.fileDB(dbFile).fileMmapEnableIfSupported().checksumHeaderBypass().make() | ||
} catch (e: DBException.VolumeIOError) { | ||
DbCreationException("Mmap enabled db could not be created", e).reportException() | ||
try { | ||
DBMaker.fileDB(dbFile).fileChannelEnable().checksumHeaderBypass().make() | ||
} catch (ee: DBException.VolumeIOError) { | ||
DbCreationException("file channel enabled db could not be created", ee).reportException() | ||
DBMaker.fileDB(dbFile).checksumHeaderBypass().make() | ||
} | ||
} | ||
} | ||
|
||
@Throws(IOException::class) | ||
private fun getDbFile(): File { | ||
val appDirs = AppDirsFactory.getInstance() | ||
val dataDir = appDirs.getUserDataDir(APP_NAME, null, APP_NAME) | ||
val folder = File(dataDir) | ||
if (!folder.exists() || !folder.isDirectory) { | ||
if (folder.exists()) { | ||
folder.delete() | ||
} | ||
try { | ||
val isPosix = FileSystems.getDefault().supportedFileAttributeViews().contains("posix") | ||
if (isPosix) { | ||
val posixAttribute = PosixFilePermissions.asFileAttribute( | ||
PosixFilePermissions.fromString("rwxr-x---") | ||
) | ||
Files.createDirectories(folder.toPath(), posixAttribute) | ||
} else { | ||
Files.createDirectories(folder.toPath()) | ||
} | ||
} catch (e: IOException) { | ||
throw IOException("Cannot create app folder at path ${folder.canonicalPath}", e) | ||
} | ||
} | ||
val dbName = "sessions.db" | ||
return File(dataDir, dbName) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package utils | ||
|
||
class DbCreationException : Exception { | ||
constructor() : super() | ||
constructor(message: String) : super(message) | ||
constructor(message: String, cause: Throwable) : super(message, cause) | ||
constructor(cause: Throwable) : super(cause) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package utils | ||
|
||
import org.jetbrains.skiko.GraphicsApi | ||
import org.jetbrains.skiko.OS | ||
import org.jetbrains.skiko.hostOs | ||
|
||
object Renderer { | ||
|
||
// private const val RENDER_API_KEY = "skiko.renderApi" | ||
|
||
// fun setRender() { | ||
// when(SystemTools.getOS()) { | ||
// OsWindows, OsLinux -> { | ||
// System.setProperty(RENDER_API_KEY, "OPENGL") | ||
// } | ||
// OsMac -> { | ||
// | ||
// } | ||
// } | ||
// } | ||
|
||
internal fun parseRenderApi(text: String?): GraphicsApi { | ||
return when (text) { | ||
"SOFTWARE_COMPAT" -> GraphicsApi.SOFTWARE_COMPAT | ||
"SOFTWARE_FAST", "DIRECT_SOFTWARE", "SOFTWARE" -> GraphicsApi.SOFTWARE_FAST | ||
"OPENGL" -> GraphicsApi.OPENGL | ||
"DIRECT3D" -> { | ||
if (hostOs == OS.Windows) GraphicsApi.DIRECT3D | ||
else throw UnsupportedOperationException("$hostOs does not support DirectX rendering API.") | ||
} | ||
"METAL" -> { | ||
if (hostOs == OS.MacOS) GraphicsApi.METAL | ||
else throw UnsupportedOperationException("$hostOs does not support Metal rendering API.") | ||
} | ||
else -> bestRenderApiForCurrentOS() | ||
} | ||
} | ||
|
||
private fun bestRenderApiForCurrentOS(): GraphicsApi { | ||
return when (hostOs) { | ||
OS.MacOS -> GraphicsApi.METAL | ||
OS.Linux -> GraphicsApi.OPENGL | ||
OS.Windows -> GraphicsApi.DIRECT3D | ||
OS.JS, OS.Ios -> TODO("commonize me") | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package utils | ||
|
||
import java.util.* | ||
|
||
object SystemTools { | ||
|
||
fun getOS(): OS { | ||
val os = System.getProperty("os.name").lowercase(Locale.getDefault()) | ||
return when { | ||
os.contains("window") -> OsWindows | ||
os.contains("nix") || os.contains("nux") || os.contains("aix") -> OsLinux | ||
os.contains("os x") || os.contains("mac") -> OsMac | ||
else -> throw UnsupportedOperationException("Operating system $os is not supported") | ||
} | ||
} | ||
|
||
} | ||
|
||
sealed interface OS | ||
object OsWindows : OS | ||
object OsLinux : OS | ||
object OsMac : OS |