示例#1
0
        public override async Task <IStorageItem> GetStorageItem()
        {
            if (StorageItem == null)
            {
                try
                {
                    Package = await FullTrustProcessController.Current.GetHyperlinkRelatedInformationAsync(InternalPathString).ConfigureAwait(false);

                    if (WIN_Native_API.CheckExist(LinkTargetPath))
                    {
                        if (WIN_Native_API.CheckType(LinkTargetPath) == StorageItemTypes.Folder)
                        {
                            return(StorageItem = await StorageFolder.GetFolderFromPathAsync(LinkTargetPath));
                        }
                        else
                        {
                            return(StorageItem = await StorageFile.GetFileFromPathAsync(LinkTargetPath));
                        }
                    }
                    else
                    {
                        return(StorageItem = null);
                    }
                }
                catch (Exception ex)
                {
                    LogTracer.Log(ex, $"Could not get hyperlink file, path: {InternalPathString}");
                    return(StorageItem = null);
                }
            }
            else
            {
                return(StorageItem);
            }
        }
示例#2
0
        public static async Task <bool> CheckExistAsync(string Path)
        {
            if (!string.IsNullOrEmpty(Path) && System.IO.Path.IsPathRooted(Path))
            {
                if (WIN_Native_API.CheckLocationAvailability(System.IO.Path.GetDirectoryName(Path)))
                {
                    return(WIN_Native_API.CheckExist(Path));
                }
                else
                {
                    try
                    {
                        string DirectoryPath = System.IO.Path.GetDirectoryName(Path);

                        if (string.IsNullOrEmpty(DirectoryPath))
                        {
                            await StorageFolder.GetFolderFromPathAsync(Path);

                            return(true);
                        }
                        else
                        {
                            StorageFolder Folder = await StorageFolder.GetFolderFromPathAsync(DirectoryPath);

                            if (await Folder.TryGetItemAsync(System.IO.Path.GetFileName(Path)) != null)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogTracer.Log(ex, "CheckExist threw an exception");
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }