예제 #1
0
        private string GetLocalVfsPath(string path)
        {
            //get full path from parameter "toPath"
            string toFullPath = GetLocalPath(path);

            //split from path based on vfsroot, overwrite old split path variable as it won't be referenced again and I don't want to assign another variable
            string[] splitpath = toFullPath.Split("VFSROOT");
            //replace from full path with corrected string and trim the start of it
            toFullPath = splitpath[1].TrimStart('/', '\\');
            //trim end of string
            toFullPath = toFullPath.TrimEnd('/', '\\');
            if (!toFullPath.Contains("LOCALFOLDER"))
            {
                //add the colon for file access
                toFullPath = toFullPath.Insert(1, ":");
            }
            else
            {
                //split the path into each folder
                string[] localpath = toFullPath.Split("\\");
                //get local state folder
                localpath[0] = UserDataPaths.GetForUser(App.user).LocalAppData + "\\Packages";
                //rejoin the parts of the path together
                toFullPath = String.Join("\\", localpath);
            }
            //retrim end of string, just as a precautionary measure
            //I tried implementing this as a trim end but it did not seem to work
            if (toFullPath.EndsWith("\\"))
            {
                toFullPath = toFullPath.Substring(0, toFullPath.Length - "\\".Length);
            }

            return(toFullPath);
        }
예제 #2
0
        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);
                }
            }
        }