2016-05-02 09:52:09 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using Bit.App.Abstractions;
|
2016-06-25 02:01:44 +03:00
|
|
|
|
using Foundation;
|
2016-07-07 05:33:50 +03:00
|
|
|
|
using SQLite;
|
2016-05-02 09:52:09 +03:00
|
|
|
|
|
2016-05-28 23:06:53 +03:00
|
|
|
|
namespace Bit.iOS.Core.Services
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
|
|
|
|
public class SqlService : ISqlService
|
|
|
|
|
{
|
2016-07-07 05:33:50 +03:00
|
|
|
|
private SQLiteConnection _connection;
|
|
|
|
|
|
|
|
|
|
public SQLiteConnection GetConnection()
|
2016-05-02 09:52:09 +03:00
|
|
|
|
{
|
2016-07-07 05:33:50 +03:00
|
|
|
|
if(_connection != null)
|
|
|
|
|
{
|
|
|
|
|
return _connection;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-02 09:52:09 +03:00
|
|
|
|
var sqliteFilename = "bitwarden.db3";
|
2016-06-25 02:01:44 +03:00
|
|
|
|
var fileManager = new NSFileManager();
|
|
|
|
|
var appGroupContainer = fileManager.GetContainerUrl("group.com.8bit.bitwarden");
|
|
|
|
|
var libraryPath = Path.Combine(appGroupContainer.Path, "Library"); // Library folder
|
2016-05-02 09:52:09 +03:00
|
|
|
|
var path = Path.Combine(libraryPath, sqliteFilename);
|
|
|
|
|
Console.WriteLine(path);
|
|
|
|
|
|
2016-07-07 05:33:50 +03:00
|
|
|
|
_connection = new SQLiteConnection(path,
|
|
|
|
|
SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.SharedCache);
|
|
|
|
|
return _connection;
|
2016-05-02 09:52:09 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|