protected override async IAsyncEnumerable <ICloudProvider> GetProviders() { string jsonPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, @"Dropbox\info.json"); var configFile = await StorageFile.GetFileFromPathAsync(jsonPath); var jsonObj = JObject.Parse(await FileIO.ReadTextAsync(configFile)); if (jsonObj.ContainsKey("personal")) { string dropboxPath = (string)jsonObj["personal"]["path"]; yield return(new CloudProvider(CloudProviders.DropBox) { Name = "Dropbox", SyncFolder = dropboxPath, }); } if (jsonObj.ContainsKey("business")) { string dropboxPath = (string)jsonObj["business"]["path"]; yield return(new CloudProvider(CloudProviders.DropBox) { Name = "Dropbox Business", SyncFolder = dropboxPath, }); } }
protected override async IAsyncEnumerable <ICloudProvider> GetProviders() { string configPathBoxDrive = Path.Combine(UserDataPaths.GetDefault().LocalAppData, @"Box\Box\data\shell\sync_root_folder.txt"); string configPathBoxSync = Path.Combine(UserDataPaths.GetDefault().LocalAppData, @"Box Sync\sync_root_folder.txt"); StorageFile configFile = await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(configPathBoxDrive).AsTask()); if (configFile is null) { configFile = await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(configPathBoxSync).AsTask()); } if (configFile is not null) { string syncPath = await FileIO.ReadTextAsync(configFile); if (!string.IsNullOrEmpty(syncPath)) { yield return(new CloudProvider(CloudProviders.Box) { Name = "Box", SyncFolder = syncPath, }); } } }
public async Task DetectAsync(List <CloudProvider> cloudProviders) { try { var infoPath = @"Box\Box\data\shell\sync_root_folder.txt"; var configPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, infoPath); var configFile = await StorageFile.GetFileFromPathAsync(configPath); var syncPath = await FileIO.ReadTextAsync(configFile); if (!string.IsNullOrEmpty(syncPath)) { cloudProviders.Add(new CloudProvider() { ID = CloudProviders.Box, Name = "Box", SyncFolder = syncPath }); } } catch { // Not detected } }
/// <summary> /// Adds the default items to the navigation page /// </summary> public void AddDefaultItems() { var udp = UserDataPaths.GetDefault(); FavoriteItems.Add(CommonPaths.DesktopPath); FavoriteItems.Add(CommonPaths.DownloadsPath); FavoriteItems.Add(udp.Documents); }
public async Task <IList <CloudProvider> > DetectAsync() { try { var infoPath = @"Mega Limited\MEGAsync\MEGAsync.cfg"; var configPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, infoPath); var configFile = await StorageFile.GetFileFromPathAsync(configPath); var parser = new IniDataParser(); var data = parser.Parse(await FileIO.ReadTextAsync(configFile)); byte[] fixedSeed = Encoding.UTF8.GetBytes("$JY/X?o=h·&%v/M("); byte[] localKey = GetLocalStorageKey(); byte[] xLocalKey = XOR(fixedSeed, localKey); var sh = SHA1.Create(); byte[] encryptionKey = sh.ComputeHash(xLocalKey); var mainSection = data.Sections.First(s => s.SectionName == "General"); string currentGroup = ""; var currentAccountKey = Hash("currentAccount", currentGroup, encryptionKey); var currentAccountStr = mainSection.Keys.First(s => s.KeyName == currentAccountKey); var currentAccountDecrypted = Decrypt(currentAccountKey, currentAccountStr.Value.Replace("\"", ""), currentGroup); var currentAccountSectionKey = Hash(currentAccountDecrypted, "", encryptionKey); var currentAccountSection = data.Sections.First(s => s.SectionName == currentAccountSectionKey); var syncKey = Hash("Syncs", currentAccountSectionKey, encryptionKey); var syncGroups = currentAccountSection.Keys.Where(s => s.KeyName.StartsWith(syncKey)).Select(x => x.KeyName.Split('\\')[1]).Distinct(); var results = new List <CloudProvider>(); foreach (var sync in syncGroups) { currentGroup = string.Join("/", currentAccountSectionKey, syncKey, sync); var syncNameKey = Hash("syncName", currentGroup, encryptionKey); var syncNameStr = currentAccountSection.Keys.First(s => s.KeyName == string.Join("\\", syncKey, sync, syncNameKey)); var syncNameDecrypted = Decrypt(syncNameKey, syncNameStr.Value.Replace("\"", ""), currentGroup); var localFolderKey = Hash("localFolder", currentGroup, encryptionKey); var localFolderStr = currentAccountSection.Keys.First(s => s.KeyName == string.Join("\\", syncKey, sync, localFolderKey)); var localFolderDecrypted = Decrypt(localFolderKey, localFolderStr.Value.Replace("\"", ""), currentGroup); results.Add(new CloudProvider() { ID = CloudProviders.Mega, Name = $"MEGA ({syncNameDecrypted})", SyncFolder = localFolderDecrypted }); } return(results); } catch { // Not detected return(Array.Empty <CloudProvider>()); } }
private static void SetupWindowsStoreApp(KalkEngine app) { try { app.KalkUserFolder = Path.Combine(UserDataPaths.GetDefault().Profile, ".kalk"); } catch { // ignore; } }
private static async Task DetectMegaAsync(List <CloudProvider> providerList) { try { //var sidstring = System.Security.Principal.WindowsIdentity.GetCurrent().User.ToString(); //using var sid = AdvApi32.ConvertStringSidToSid(sidstring); var infoPath = @"Mega Limited\MEGAsync\MEGAsync.cfg"; var configPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, infoPath); var configFile = await StorageFile.GetFileFromPathAsync(configPath); var parser = new IniDataParser(); var data = parser.Parse(await FileIO.ReadTextAsync(configFile)); byte[] fixedSeed = Encoding.UTF8.GetBytes("$JY/X?o=h·&%v/M("); byte[] localKey = GetLocalStorageKey(); /*sid.GetBinaryForm()*/ byte[] xLocalKey = XOR(fixedSeed, localKey); var sh = SHA1.Create(); byte[] hLocalKey = sh.ComputeHash(xLocalKey); var encryptionKey = hLocalKey; var mainSection = data.Sections.First(s => s.SectionName == "General"); string currentGroup = ""; var currentAccountKey = Hash("currentAccount", currentGroup, encryptionKey); var currentAccountStr = mainSection.Keys.First(s => s.KeyName == currentAccountKey); var currentAccountDecrypted = Decrypt(currentAccountKey, currentAccountStr.Value.Replace("\"", ""), currentGroup); var currentAccountSectionKey = Hash(currentAccountDecrypted, "", encryptionKey); var currentAccountSection = data.Sections.First(s => s.SectionName == currentAccountSectionKey); var syncKey = Hash("Syncs", currentAccountSectionKey, encryptionKey); var syncGroups = currentAccountSection.Keys.Where(s => s.KeyName.StartsWith(syncKey)).Select(x => x.KeyName.Split('\\')[1]).Distinct(); foreach (var sync in syncGroups) { currentGroup = string.Join("/", currentAccountSectionKey, syncKey, sync); var syncNameKey = Hash("syncName", currentGroup, encryptionKey); var syncNameStr = currentAccountSection.Keys.First(s => s.KeyName == string.Join("\\", syncKey, sync, syncNameKey)); var syncNameDecrypted = Decrypt(syncNameKey, syncNameStr.Value.Replace("\"", ""), currentGroup); var localFolderKey = Hash("localFolder", currentGroup, encryptionKey); var localFolderStr = currentAccountSection.Keys.First(s => s.KeyName == string.Join("\\", syncKey, sync, localFolderKey)); var localFolderDecrypted = Decrypt(localFolderKey, localFolderStr.Value.Replace("\"", ""), currentGroup); providerList.Add(new CloudProvider() { ID = KnownCloudProviders.Mega, SyncFolder = localFolderDecrypted, Name = $"MEGA ({syncNameDecrypted})" }); } } catch { // Not detected } }
protected override async IAsyncEnumerable <ICloudProvider> GetProviders() { string userPath = UserDataPaths.GetDefault().Profile; string iCloudPath = Path.Combine(userPath, "iCloudDrive"); var driveFolder = await StorageFolder.GetFolderFromPathAsync(iCloudPath); yield return(new CloudProvider(CloudProviders.AppleCloud) { Name = "iCloud", SyncFolder = driveFolder.Path, }); }
private async void ButtonBase_OnClick(object sender, RoutedEventArgs e) { var folder = await StorageFolder.GetFolderFromPathAsync(UserDataPaths.GetDefault().Music); LoadingService.LoadingStart(); StorageFolder assets = await folder.GetFolderAsync("Backups"); (await new BackupServices().CreateBackup(assets.Path)).Success(x => { _pageUtilities.ShowMessageDialog($"El backup {x}, fue creado correctamente"); GetFiles(); }); }
private static async Task DetectGoogleDriveAsync(List <CloudProvider> providerList) { try { // Google Drive's sync database can be in a couple different locations. Go find it. string appDataPath = UserDataPaths.GetDefault().LocalAppData; string dbPath = @"Google\Drive\user_default\sync_config.db"; var configFile = await StorageFile.GetFileFromPathAsync(Path.Combine(appDataPath, dbPath)); await configFile.CopyAsync(ApplicationData.Current.TemporaryFolder, "google_drive.db", NameCollisionOption.ReplaceExisting); var syncDbPath = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, "google_drive.db"); // Build the connection and sql command SQLitePCL.Batteries_V2.Init(); using (var con = new SqliteConnection($"Data Source='{syncDbPath}'")) using (var cmd = new SqliteCommand("select * from data where entry_key='local_sync_root_path'", con)) { // Open the connection and execute the command con.Open(); var reader = cmd.ExecuteReader(); reader.Read(); // Extract the data from the reader string path = reader["data_value"]?.ToString(); if (string.IsNullOrWhiteSpace(path)) { return; } // By default, the path will be prefixed with "\\?\" (unless another app has explicitly changed it). // \\?\ indicates to Win32 that the filename may be longer than MAX_PATH (see MSDN). // Parts of .NET (e.g. the File class) don't handle this very well, so remove this prefix. if (path.StartsWith(@"\\?\")) { path = path.Substring(@"\\?\".Length); } providerList.Add(new CloudProvider() { ID = KnownCloudProviders.GoogleDrive, SyncFolder = path, Name = $"Google Drive" }); } } catch { // Not detected } }
private async Task GetFiles() { var folder = await StorageFolder.GetFolderFromPathAsync(UserDataPaths.GetDefault().Music); StorageFolder assets = await folder.GetFolderAsync("Backups"); Backups.Clear(); var files = await assets.GetFilesAsync(); foreach (var fileToAdd in files) { Backups.Add(fileToAdd); } }
/// <summary> /// Gets the icon for the items in the navigation sidebar /// </summary> /// <param name="path">The path in the sidebar</param> /// <returns>The icon code</returns> public static string GetItemIcon(string path, string fallback = "\uE8B7") { string iconCode = fallback; if (path != null) { // TODO: do library check based on the library file path? var udp = UserDataPaths.GetDefault(); if (path.Equals(AppSettings.DesktopPath, StringComparison.OrdinalIgnoreCase)) { iconCode = "\uE8FC"; } else if (path.Equals(AppSettings.DownloadsPath, StringComparison.OrdinalIgnoreCase)) { iconCode = "\uE896"; } else if (path.Equals(udp.Documents, StringComparison.OrdinalIgnoreCase)) { iconCode = "\uE8A5"; } else if (path.Equals(udp.Pictures, StringComparison.OrdinalIgnoreCase)) { iconCode = "\uEB9F"; } else if (path.Equals(udp.Music, StringComparison.OrdinalIgnoreCase)) { iconCode = "\uEC4F"; } else if (path.Equals(udp.Videos, StringComparison.OrdinalIgnoreCase)) { iconCode = "\uE8B2"; } else if (path.Equals(AppSettings.NetworkFolderPath, StringComparison.OrdinalIgnoreCase)) { iconCode = "\uE8CE"; } else if (Path.GetPathRoot(path).Equals(path, StringComparison.OrdinalIgnoreCase)) { iconCode = "\uEDA2"; } } return(iconCode); }
public static SvgImageSource GetIconUri(string path) { SvgImageSource iconCode = new SvgImageSource(new Uri("ms-appx:///Assets/FluentIcons/Folder.svg")); if (path != null) { // TODO: do library check based on the library file path? var udp = UserDataPaths.GetDefault(); if (path.Equals(AppSettings.DesktopPath, StringComparison.OrdinalIgnoreCase)) { iconCode = new SvgImageSource(new Uri("ms-appx:///Assets/FluentIcons/Desktop.svg")); } else if (path.Equals(AppSettings.DownloadsPath, StringComparison.OrdinalIgnoreCase)) { iconCode = new SvgImageSource(new Uri("ms-appx:///Assets/FluentIcons/Downloads.svg")); } else if (path.Equals(udp.Documents, StringComparison.OrdinalIgnoreCase)) { iconCode = new SvgImageSource(new Uri("ms-appx:///Assets/FluentIcons/Documents.svg")); } else if (path.Equals(udp.Pictures, StringComparison.OrdinalIgnoreCase)) { iconCode = new SvgImageSource(new Uri("ms-appx:///Assets/FluentIcons/Pictures.svg")); } else if (path.Equals(udp.Music, StringComparison.OrdinalIgnoreCase)) { iconCode = new SvgImageSource(new Uri("ms-appx:///Assets/FluentIcons/Music.svg")); } else if (path.Equals(udp.Videos, StringComparison.OrdinalIgnoreCase)) { iconCode = new SvgImageSource(new Uri("ms-appx:///Assets/FluentIcons/Videos.svg")); } else if (path.Equals(AppSettings.NetworkFolderPath, StringComparison.OrdinalIgnoreCase)) { iconCode = new SvgImageSource(new Uri("ms-appx:///Assets/FluentIcons/Drive_Network.svg")); } else if (Path.GetPathRoot(path).Equals(path, StringComparison.OrdinalIgnoreCase)) { iconCode = new SvgImageSource(new Uri("ms-appx:///Assets/FluentIcons/Drive_USB.svg")); } } return(iconCode); }
public async Task DetectAsync(List <CloudProvider> cloudProviders) { try { var userPath = UserDataPaths.GetDefault().Profile; var iCloudPath = "iCloudDrive"; var driveFolder = await StorageFolder.GetFolderFromPathAsync(Path.Combine(userPath, iCloudPath)); cloudProviders.Add(new CloudProvider() { ID = CloudProviders.AppleCloud, Name = "iCloud", SyncFolder = driveFolder.Path }); } catch { // Not detected } }
private static async Task DetectiCloudAsync(List <CloudProvider> providerList) { try { var userPath = UserDataPaths.GetDefault().Profile; var iCloudPath = "iCloudDrive"; var driveFolder = await StorageFolder.GetFolderFromPathAsync(Path.Combine(userPath, iCloudPath)); providerList.Add(new CloudProvider() { ID = KnownCloudProviders.iCloud, SyncFolder = driveFolder.Path, Name = "iCloud" }); } catch { // Not detected } }
public async Task <IList <CloudProvider> > DetectAsync() { try { var infoPath = @"Dropbox\info.json"; var jsonPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, infoPath); var configFile = await StorageFile.GetFileFromPathAsync(jsonPath); var jsonObj = JObject.Parse(await FileIO.ReadTextAsync(configFile)); var results = new List <CloudProvider>(); if (jsonObj.ContainsKey("personal")) { var dropboxPath = (string)jsonObj["personal"]["path"]; results.Add(new CloudProvider() { ID = CloudProviders.DropBox, Name = "Dropbox", SyncFolder = dropboxPath }); } if (jsonObj.ContainsKey("business")) { var dropboxPath = (string)jsonObj["business"]["path"]; results.Add(new CloudProvider() { ID = CloudProviders.DropBox, Name = "Dropbox Business", SyncFolder = dropboxPath }); } return(results); } catch { // Not detected return(Array.Empty <CloudProvider>()); } }
public async Task <IList <CloudProvider> > DetectAsync() { try { var userPath = UserDataPaths.GetDefault().Profile; var iCloudPath = "iCloudDrive"; var driveFolder = await StorageFolder.GetFolderFromPathAsync(Path.Combine(userPath, iCloudPath)); return(new[] { new CloudProvider() { ID = CloudProviders.AppleCloud, Name = "iCloud", SyncFolder = driveFolder.Path } }); } catch { // Not detected return(Array.Empty <CloudProvider>()); } }
//Getting the Inventory.xml and giving it as an input //to the API, getting back the list of updates public async Task <List <UpdateInfo> > GetSwbUpdatesAsync() { List <UpdateInfo> updatesInfoList = null; using (var client = new HttpClient()) { //IP of the azure VM in cloud client.BaseAddress = new Uri("http://137.117.96.234/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var userDataPath = UserDataPaths.GetDefault(); var desktopPath = userDataPath.Desktop; var folderPath = desktopPath + @"\IC"; var storageFolder = await StorageFolder.GetFolderFromPathAsync(folderPath); var file = await storageFolder.GetFileAsync("ICJson.json"); //Reading the xml from the file stream string icReport; using (Stream fileStream = await file.OpenStreamForReadAsync()) { StreamReader streamReader = new StreamReader(fileStream); icReport = await streamReader.ReadToEndAsync(); } //Enabling SSL on the API might not work and throw invalid certificate error //Exception: "The certificate authority is invalid or incorrect" var response = await client.PostAsJsonAsync("api/PlatformInfo/SwbUpdatesJSON", icReport); if (response.IsSuccessStatusCode) { var stream = await response.Content.ReadAsStringAsync(); updatesInfoList = JsonConvert.DeserializeObject <List <UpdateInfo> >(stream); } } return(updatesInfoList); }
private static async Task DetectDropboxAsync(List <CloudProvider> providerList) { try { var infoPath = @"Dropbox\info.json"; var jsonPath = Path.Combine(UserDataPaths.GetDefault().LocalAppData, infoPath); var configFile = await StorageFile.GetFileFromPathAsync(jsonPath); var jsonObj = JObject.Parse(await FileIO.ReadTextAsync(configFile)); var dropboxPath = (string)(jsonObj["personal"]["path"]); providerList.Add(new CloudProvider() { ID = KnownCloudProviders.DropBox, SyncFolder = dropboxPath, Name = "Dropbox" }); } catch { // Not detected } }
public async Task <IList <CloudProvider> > DetectAsync() { try { var infoPathBoxDrive = @"Box\Box\data\shell\sync_root_folder.txt"; var configPathBoxDrive = Path.Combine(UserDataPaths.GetDefault().LocalAppData, infoPathBoxDrive); var infoPathBoxSync = @"Box Sync\sync_root_folder.txt"; var configPathBoxSync = Path.Combine(UserDataPaths.GetDefault().LocalAppData, infoPathBoxSync); StorageFile configFile = await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(configPathBoxDrive).AsTask()); if (configFile == null) { configFile = await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(configPathBoxSync).AsTask()); } if (configFile != null) { var syncPath = await FileIO.ReadTextAsync(configFile); if (!string.IsNullOrEmpty(syncPath)) { return(new[] { new CloudProvider() { ID = CloudProviders.Box, Name = "Box", SyncFolder = syncPath } }); } } return(Array.Empty <CloudProvider>()); } catch { // Not detected return(Array.Empty <CloudProvider>()); } }
private void ButtonBase_OnClick(object sender, Windows.UI.Xaml.RoutedEventArgs e) { var folder = StorageFolder.GetFolderFromPathAsync(UserDataPaths.GetDefault().Music).GetAwaiter().GetResult(); StorageFolder assets = folder.GetFolderAsync("Backups").GetAwaiter().GetResult(); Document doc = new Document(); doc.Open(); doc.Add(new Paragraph("Hello World")); doc.Close(); PdfReader reader = new PdfReader("Chapter1_Example1.pdf"); string text = string.Empty; for (int page = 1; page <= reader.NumberOfPages; page++) { text += PdfTextExtractor.GetTextFromPage(reader, page); } reader.Close(); Console.WriteLine(text); }
private static string ReplaceEnvironmentVariables(string args) { if (args.Contains("%homepath%", StringComparison.OrdinalIgnoreCase)) { args = args.Replace("%homepath%", Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), StringComparison.OrdinalIgnoreCase); } if (args.Contains("%localappdata%", StringComparison.OrdinalIgnoreCase)) { args = args.Replace("%localappdata%", UserDataPaths.GetDefault().LocalAppData, StringComparison.OrdinalIgnoreCase); } if (args.Contains("%temp%", StringComparison.OrdinalIgnoreCase)) { args = args.Replace("%temp%", (string)Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Environment", "TEMP", Environment.GetEnvironmentVariable("temp")), StringComparison.OrdinalIgnoreCase); } if (args.Contains("%tmp%", StringComparison.OrdinalIgnoreCase)) { args = args.Replace("%tmp%", (string)Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Environment", "TEMP", Environment.GetEnvironmentVariable("tmp")), StringComparison.OrdinalIgnoreCase); } return(Environment.ExpandEnvironmentVariables(args)); }
protected override async IAsyncEnumerable <ICloudProvider> GetProviders() { // Google Drive's sync database can be in a couple different locations. Go find it. string appDataPath = UserDataPaths.GetDefault().LocalAppData; var configFile = await StorageFile.GetFileFromPathAsync(Path.Combine(appDataPath, @"Google\DriveFS\root_preference_sqlite.db")); await configFile.CopyAsync(ApplicationData.Current.TemporaryFolder, "google_drive.db", NameCollisionOption.ReplaceExisting); var syncDbPath = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, "google_drive.db"); // Build the connection and sql command SQLitePCL.Batteries_V2.Init(); using var database = new SqliteConnection($"Data Source='{syncDbPath}'"); using var cmdRoot = new SqliteCommand("SELECT * FROM roots", database); using var cmdMedia = new SqliteCommand("SELECT * FROM media WHERE fs_type=10", database); // Open the connection and execute the command database.Open(); var reader = cmdRoot.ExecuteReader(); // Google synced folders while (reader.Read()) { // Extract the data from the reader string path = reader["last_seen_absolute_path"]?.ToString(); if (string.IsNullOrWhiteSpace(path)) { continue; } // By default, the path will be prefixed with "\\?\" (unless another app has explicitly changed it). // \\?\ indicates to Win32 that the filename may be longer than MAX_PATH (see MSDN). // Parts of .NET (e.g. the File class) don't handle this very well, so remove this prefix. if (path.StartsWith(@"\\?\", StringComparison.Ordinal)) { path = path.Substring(@"\\?\".Length); } var folder = await StorageFolder.GetFolderFromPathAsync(path); string title = reader["title"]?.ToString() ?? folder.Name; yield return(new CloudProvider(CloudProviders.GoogleDrive) { Name = $"Google Drive ({title})", SyncFolder = path, }); } reader = cmdMedia.ExecuteReader(); // Google virtual drive while (reader.Read()) { string path = reader["last_mount_point"]?.ToString(); if (string.IsNullOrWhiteSpace(path)) { continue; } var folder = await StorageFolder.GetFolderFromPathAsync(path); string title = reader["name"]?.ToString() ?? folder.Name; string iconPath = Path.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "Google", "Drive File Stream", "drive_fs.ico"); StorageFile iconFile = await FilesystemTasks.Wrap(() => StorageFile.GetFileFromPathAsync(iconPath).AsTask()); yield return(new CloudProvider(CloudProviders.GoogleDrive) { Name = title, SyncFolder = path, IconData = iconFile is not null ? await iconFile.ToByteArrayAsync() : null, });
public async Task <IList <CloudProvider> > DetectAsync() { try { // Google Drive's sync database can be in a couple different locations. Go find it. string appDataPath = UserDataPaths.GetDefault().LocalAppData; string dbPath = @"Google\DriveFS\root_preference_sqlite.db"; var configFile = await StorageFile.GetFileFromPathAsync(Path.Combine(appDataPath, dbPath)); await configFile.CopyAsync(ApplicationData.Current.TemporaryFolder, "google_drive.db", NameCollisionOption.ReplaceExisting); var syncDbPath = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, "google_drive.db"); // Build the connection and sql command SQLitePCL.Batteries_V2.Init(); using (var con = new SqliteConnection($"Data Source='{syncDbPath}'")) using (var cmd = new SqliteCommand("select * from roots", con)) { // Open the connection and execute the command con.Open(); var reader = cmd.ExecuteReader(); var results = new List <CloudProvider>(); while (reader.Read()) { // Extract the data from the reader string path = reader["last_seen_absolute_path"]?.ToString(); if (string.IsNullOrWhiteSpace(path)) { return(Array.Empty <CloudProvider>()); } // By default, the path will be prefixed with "\\?\" (unless another app has explicitly changed it). // \\?\ indicates to Win32 that the filename may be longer than MAX_PATH (see MSDN). // Parts of .NET (e.g. the File class) don't handle this very well, so remove this prefix. if (path.StartsWith(@"\\?\", StringComparison.Ordinal)) { path = path.Substring(@"\\?\".Length); } var folder = await StorageFolder.GetFolderFromPathAsync(path); var googleCloud = new CloudProvider() { ID = CloudProviders.GoogleDrive, SyncFolder = path }; string title = reader["title"]?.ToString() ?? folder.Name; googleCloud.Name = $"Google Drive ({title})"; results.Add(googleCloud); } return(results); } } catch { // Not detected return(Array.Empty <CloudProvider>()); } }
protected override async IAsyncEnumerable <ICloudProvider> GetProviders() { /* Synology Drive stores its information on some files, but we only need sys.sqlite, which is placed on %LocalAppData%\SynologyDrive\data\db * In this database we need "connection_table" and "session_table" tables: * connection_table has the ids of each connection in the field "id", and the type of connection in the field "conn_type" (1 for sync tasks and 2 for backups) * Also it has "host_name" field where it's placed the name of each server. * session_table has the next fields: * "conn_id", which has the id that we check on connection_table to see if it's a sync or backup task * "remote_path", which has the server folder. Currently it's not needed, just adding in case in the future is needed. * "sync_folder", which has the local folder to sync. */ string appDataPath = UserDataPaths.GetDefault().LocalAppData; var configFile = await StorageFile.GetFileFromPathAsync(Path.Combine(appDataPath, @"SynologyDrive\data\db\sys.sqlite")); await configFile.CopyAsync(ApplicationData.Current.TemporaryFolder, "synology_drive.db", NameCollisionOption.ReplaceExisting); var syncDbPath = Path.Combine(ApplicationData.Current.TemporaryFolder.Path, "synology_drive.db"); // Build the connection and sql command SQLitePCL.Batteries_V2.Init(); using var database = new SqliteConnection($"Data Source='{syncDbPath}'"); using var cmdConnection = new SqliteCommand("SELECT * FROM connection_table", database); using var cmdTable = new SqliteCommand("SELECT * FROM session_table", database); // Open the connection and execute the command database.Open(); var connections = new Dictionary <string, (string ConnectionType, string HostName)>(); var reader = cmdConnection.ExecuteReader(); while (reader.Read()) { var connection = ( ConnectionType : reader["conn_type"]?.ToString(), HostName : reader["host_name"]?.ToString() ); connections.Add(reader["id"]?.ToString(), connection); } reader = cmdTable.ExecuteReader(); while (reader.Read()) { // Extract the data from the reader if (connections[reader["conn_id"]?.ToString()].ConnectionType is "1") { string path = reader["sync_folder"]?.ToString(); if (string.IsNullOrWhiteSpace(path)) { continue; } var folder = await StorageFolder.GetFolderFromPathAsync(path); yield return(new CloudProvider(CloudProviders.SynologyDrive) { SyncFolder = path, Name = $"Synology Drive - {connections[reader["conn_id"]?.ToString()].HostName} ({folder.Name})", }); } } }
public static async Task LoadLibraryFoldersAsync() { if (Interlocked.Exchange(ref LoadLibraryLockResource, 1) == 0) { try { if (!IsLibaryLoaded) { IsLibaryLoaded = true; if (!ApplicationData.Current.LocalSettings.Values.ContainsKey("IsLibraryInitialized")) { try { IReadOnlyList <User> UserList = await User.FindAllAsync(); UserDataPaths DataPath = UserList.FirstOrDefault((User) => User.AuthenticationStatus == UserAuthenticationStatus.LocallyAuthenticated && User.Type == UserType.LocalUser) is User CurrentUser ? UserDataPaths.GetForUser(CurrentUser) : UserDataPaths.GetDefault(); try { if (!string.IsNullOrEmpty(DataPath.Downloads)) { await SQLite.Current.SetLibraryPathAsync(DataPath.Downloads, LibraryType.Downloads); } if (!string.IsNullOrEmpty(DataPath.Desktop)) { await SQLite.Current.SetLibraryPathAsync(DataPath.Desktop, LibraryType.Desktop); } if (!string.IsNullOrEmpty(DataPath.Videos)) { await SQLite.Current.SetLibraryPathAsync(DataPath.Videos, LibraryType.Videos); } if (!string.IsNullOrEmpty(DataPath.Pictures)) { await SQLite.Current.SetLibraryPathAsync(DataPath.Pictures, LibraryType.Pictures); } if (!string.IsNullOrEmpty(DataPath.Documents)) { await SQLite.Current.SetLibraryPathAsync(DataPath.Documents, LibraryType.Document); } if (!string.IsNullOrEmpty(DataPath.Music)) { await SQLite.Current.SetLibraryPathAsync(DataPath.Music, LibraryType.Music); } if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("OneDrive"))) { await SQLite.Current.SetLibraryPathAsync(Environment.GetEnvironmentVariable("OneDrive"), LibraryType.OneDrive); } } catch (Exception ex) { LogTracer.Log(ex, "An error was threw when getting library folder (In initialize)"); } } catch (Exception ex) { LogTracer.Log(ex, "An error was threw when try to get 'UserDataPath' (In initialize)"); string DesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); if (!string.IsNullOrEmpty(DesktopPath)) { await SQLite.Current.SetLibraryPathAsync(DesktopPath, LibraryType.Desktop); } string VideoPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos); if (!string.IsNullOrEmpty(VideoPath)) { await SQLite.Current.SetLibraryPathAsync(VideoPath, LibraryType.Videos); } string PicturesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); if (!string.IsNullOrEmpty(PicturesPath)) { await SQLite.Current.SetLibraryPathAsync(PicturesPath, LibraryType.Pictures); } string DocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (!string.IsNullOrEmpty(DocumentsPath)) { await SQLite.Current.SetLibraryPathAsync(DocumentsPath, LibraryType.Document); } string MusicPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); if (!string.IsNullOrEmpty(MusicPath)) { await SQLite.Current.SetLibraryPathAsync(MusicPath, LibraryType.Music); } string OneDrivePath = Environment.GetEnvironmentVariable("OneDrive"); if (!string.IsNullOrEmpty(OneDrivePath)) { await SQLite.Current.SetLibraryPathAsync(OneDrivePath, LibraryType.OneDrive); } } finally { ApplicationData.Current.LocalSettings.Values["IsLibraryInitialized"] = true; } } else { try { IReadOnlyList <User> UserList = await User.FindAllAsync(); UserDataPaths DataPath = UserList.FirstOrDefault((User) => User.AuthenticationStatus == UserAuthenticationStatus.LocallyAuthenticated && User.Type == UserType.LocalUser) is User CurrentUser ? UserDataPaths.GetForUser(CurrentUser) : UserDataPaths.GetDefault(); try { if (!string.IsNullOrEmpty(DataPath.Downloads)) { await SQLite.Current.UpdateLibraryAsync(DataPath.Downloads, LibraryType.Downloads); } if (!string.IsNullOrEmpty(DataPath.Desktop)) { await SQLite.Current.UpdateLibraryAsync(DataPath.Desktop, LibraryType.Desktop); } if (!string.IsNullOrEmpty(DataPath.Videos)) { await SQLite.Current.UpdateLibraryAsync(DataPath.Videos, LibraryType.Videos); } if (!string.IsNullOrEmpty(DataPath.Pictures)) { await SQLite.Current.UpdateLibraryAsync(DataPath.Pictures, LibraryType.Pictures); } if (!string.IsNullOrEmpty(DataPath.Documents)) { await SQLite.Current.UpdateLibraryAsync(DataPath.Documents, LibraryType.Document); } if (!string.IsNullOrEmpty(DataPath.Music)) { await SQLite.Current.UpdateLibraryAsync(DataPath.Music, LibraryType.Music); } if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("OneDrive"))) { await SQLite.Current.UpdateLibraryAsync(Environment.GetEnvironmentVariable("OneDrive"), LibraryType.OneDrive); } } catch (Exception ex) { LogTracer.Log(ex, "An error was threw when getting library folder (Not in initialize)"); } } catch (Exception ex) { LogTracer.Log(ex, "An error was threw when try to get 'UserDataPath' (Not in initialize)"); string DesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); if (!string.IsNullOrEmpty(DesktopPath)) { await SQLite.Current.UpdateLibraryAsync(DesktopPath, LibraryType.Desktop); } string VideoPath = Environment.GetFolderPath(Environment.SpecialFolder.MyVideos); if (!string.IsNullOrEmpty(VideoPath)) { await SQLite.Current.UpdateLibraryAsync(VideoPath, LibraryType.Videos); } string PicturesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); if (!string.IsNullOrEmpty(PicturesPath)) { await SQLite.Current.UpdateLibraryAsync(PicturesPath, LibraryType.Pictures); } string DocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (!string.IsNullOrEmpty(DocumentsPath)) { await SQLite.Current.UpdateLibraryAsync(DocumentsPath, LibraryType.Document); } string MusicPath = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); if (!string.IsNullOrEmpty(MusicPath)) { await SQLite.Current.UpdateLibraryAsync(MusicPath, LibraryType.Music); } string OneDrivePath = Environment.GetEnvironmentVariable("OneDrive"); if (!string.IsNullOrEmpty(OneDrivePath)) { await SQLite.Current.UpdateLibraryAsync(OneDrivePath, LibraryType.OneDrive); } } } Queue <string> ErrorList = new Queue <string>(); foreach ((string, LibraryType)Library in await SQLite.Current.GetLibraryPathAsync()) { try { LibraryFolderList.Add(await LibraryFolder.CreateAsync(Library.Item1, Library.Item2)); } catch (Exception) { ErrorList.Enqueue(Library.Item1); await SQLite.Current.DeleteLibraryAsync(Library.Item1); } } await JumpListController.Current.AddItemAsync(JumpListGroup.Library, LibraryFolderList.Where((Library) => Library.Type == LibraryType.UserCustom).Select((Library) => Library.Folder.Path).ToArray()); if (ErrorList.Count > 0) { LibraryNotFound?.Invoke(null, ErrorList); } } } finally { _ = Interlocked.Exchange(ref LoadLibraryLockResource, 0); } } }
private static string GetFolderPathCoreCurrent(SpecialFolder folder) { // While all of these give back real paths, most of them are not accessible // from an appcontainer currently (they will give access denied) switch (folder) { case SpecialFolder.ApplicationData: return(UserDataPaths.GetDefault().RoamingAppData); case SpecialFolder.CommonApplicationData: return(AppDataPaths.GetDefault().ProgramData); case SpecialFolder.LocalApplicationData: return(AppDataPaths.GetDefault().LocalAppData); case SpecialFolder.Cookies: return(AppDataPaths.GetDefault().Cookies); case SpecialFolder.Desktop: return(AppDataPaths.GetDefault().Desktop); case SpecialFolder.Favorites: return(AppDataPaths.GetDefault().Favorites); case SpecialFolder.History: return(AppDataPaths.GetDefault().History); case SpecialFolder.InternetCache: return(AppDataPaths.GetDefault().InternetCache); case SpecialFolder.MyMusic: return(UserDataPaths.GetDefault().Music); case SpecialFolder.MyPictures: return(UserDataPaths.GetDefault().Pictures); case SpecialFolder.MyVideos: return(UserDataPaths.GetDefault().Videos); case SpecialFolder.Recent: return(UserDataPaths.GetDefault().Recent); case SpecialFolder.System: return(SystemDataPaths.GetDefault().System); case SpecialFolder.Templates: return(UserDataPaths.GetDefault().Templates); case SpecialFolder.DesktopDirectory: return(UserDataPaths.GetDefault().Desktop); case SpecialFolder.Personal: return(UserDataPaths.GetDefault().Documents); case SpecialFolder.CommonDocuments: return(SystemDataPaths.GetDefault().PublicDocuments); case SpecialFolder.CommonMusic: return(SystemDataPaths.GetDefault().PublicMusic); case SpecialFolder.CommonPictures: return(SystemDataPaths.GetDefault().PublicPictures); case SpecialFolder.CommonDesktopDirectory: return(SystemDataPaths.GetDefault().PublicDesktop); case SpecialFolder.CommonVideos: return(SystemDataPaths.GetDefault().PublicVideos); case SpecialFolder.UserProfile: return(UserDataPaths.GetDefault().Profile); case SpecialFolder.SystemX86: return(SystemDataPaths.GetDefault().SystemX86); case SpecialFolder.Windows: return(SystemDataPaths.GetDefault().Windows); // The following aren't available on WinRT. Our default behavior // is string.Empty for paths that aren't available. // // case SpecialFolder.Programs: // case SpecialFolder.MyComputer: // case SpecialFolder.SendTo: // case SpecialFolder.StartMenu: // case SpecialFolder.Startup: // case SpecialFolder.ProgramFiles: // case SpecialFolder.CommonProgramFiles: // case SpecialFolder.AdminTools: // case SpecialFolder.CDBurning: // case SpecialFolder.CommonAdminTools: // case SpecialFolder.CommonOemLinks: // case SpecialFolder.CommonStartMenu: // case SpecialFolder.CommonPrograms: // case SpecialFolder.CommonStartup: // case SpecialFolder.CommonTemplates: // case SpecialFolder.Fonts: // case SpecialFolder.NetworkShortcuts: // case SpecialFolder.PrinterShortcuts: // case SpecialFolder.CommonProgramFilesX86: // case SpecialFolder.ProgramFilesX86: // case SpecialFolder.Resources: // case SpecialFolder.LocalizedResources: default: return(string.Empty); } }