Exemple #1
0
        public static async Task<string> SetupChmFileFromOneDrive(LiveConnectClient client, 
            IProgress<LiveOperationProgress> progressHandler,
            System.Threading.CancellationToken ctoken,
            string id, string name, string path)
        {
            ChmFile ret = new ChmFile();
            ret.Key = Guid.NewGuid().ToString("N");
            ret.HasThumbnail = false;
            Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;

            StorageFile file = await localFolder.CreateFileAsync(ret.Key + ChmFileExtension, CreationCollisionOption.ReplaceExisting);
            LiveDownloadOperationResult result = await client.BackgroundDownloadAsync(id + "/content", file, ctoken, progressHandler);
            
            try
            {
                ret.Chm = await LoadChm(file.Path, false);
                MetaInfo meta = new MetaInfo();
                meta.SetOriginalPath(path);
                if (ret.Chm.Title != null)
                {
                    meta.SetDisplayName(ret.Chm.Title);
                }
                else
                {
                    meta.SetDisplayName(System.IO.Path.GetFileNameWithoutExtension(name));
                }
                ret.ChmMeta = meta;
                await ret.Save();
                FileHistory.AddToHistory(ret.Key);
            }
            catch
            {
                ret.Chm = null;
            }
            if (ret.Chm == null)
            {
                await MetaInfo.DeleteMetaFile(ret.Key);
                await DeleteFile(ret.Key);
                return null;
            }
            return ret.Key;
        }
Exemple #2
0
 public static async Task<string> SetupChmFileFromPhone(IStorageFile storageFile)
 {
     ChmFile ret = new ChmFile();
     Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
     ret.Key = Guid.NewGuid().ToString("N");
     ret.HasThumbnail = false;
     var file = await storageFile.CopyAsync(localFolder, ret.Key + ChmFileExtension);
     try
     {
         ret.Chm = await LoadChm(file.Path, false);
         MetaInfo meta = new MetaInfo();
         meta.SetOriginalPath(storageFile.Path);
         if (ret.Chm.Title != null)
         {
             meta.SetDisplayName(ret.Chm.Title);
         }
         else
         {
             meta.SetDisplayName(System.IO.Path.GetFileNameWithoutExtension(storageFile.Name));
         }
         ret.ChmMeta = meta;
         await ret.Save();
         FileHistory.AddToHistory(ret.Key);
     }
     catch
     {
         ret.Chm = null;
     }
     if (ret.Chm == null)
     {
         await MetaInfo.DeleteMetaFile(ret.Key);
         await DeleteFile(ret.Key);
         return null;
     }
     return ret.Key;
 }