Exemplo n.º 1
0
        public async void OpenFile(TelegramFileInfo fileInfo)
        {
            var store = IsolatedStorageFile.GetUserStoreForApplication();

            if (store.FileExists(fileInfo.Name))
            {
                var file = await ApplicationData.Current.LocalFolder.GetFileAsync(fileInfo.Name);

                if (file != null)
                {
                    Launcher.LaunchFileAsync(file);
                    return;
                }
            }
        }
Exemplo n.º 2
0
        private long GetDatabaseLength(IsolatedStorageFile store, List <TelegramFileInfo> files)
        {
            long length2           = 0L;
            var  databaseFileNames = GetDatabaseFileNames();

            foreach (var fileName in databaseFileNames)
            {
                try
                {
                    var fileInfo = new TelegramFileInfo {
                        Name = fileName
                    };
                    if (store.FileExists(fileName))
                    {
                        using (
                            var file = new IsolatedStorageFileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read,
                                                                     store))
                        {
                            var lastAccessTime = store.GetLastAccessTime(fileName);
                            var lastWriteTime  = store.GetLastWriteTime(fileName);
                            fileInfo.Length = file.Length;
                            //if (IsValidCacheFileName(fileName))
                            {
                                length2 += file.Length;
                                fileInfo.IsValidCacheFileName = true;
                            }
                        }
                    }
                    files.Add(fileInfo);
                }
                catch (Exception ex)
                {
                    TLUtils.WriteException("CalculateCacheSizeAsync OpenFile: " + fileName, ex);
                }
            }

            return(length2);
        }
Exemplo n.º 3
0
        private void CalculateCacheSizeAsync(Action <long> callback)
        {
            BeginOnThreadPool(() =>
            {
                _isCalculating = true;

                var length = 0L;
                var files  = new List <TelegramFileInfo>();
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    var fileNames = store.GetFileNames();

                    foreach (var fileName in fileNames)
                    {
                        try
                        {
                            var fileInfo = new TelegramFileInfo {
                                Name = fileName
                            };
                            if (store.FileExists(fileName))
                            {
                                using (var file = new IsolatedStorageFileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, store))
                                {
                                    fileInfo.Length = file.Length;
                                    if (IsValidCacheFileName(fileName))
                                    {
                                        length += file.Length;
                                        fileInfo.IsValidCacheFileName = true;
                                    }
                                }
                            }
                            files.Add(fileInfo);
                        }
                        catch (Exception ex)
                        {
                            TLUtils.WriteException("CalculateCacheSizeAsync OpenFile: " + fileName, ex);
                        }
                    }

                    var directoryNames = store.GetDirectoryNames();
                    foreach (var fileName in directoryNames)
                    {
                        try
                        {
                            var fileInfo = new TelegramFileInfo {
                                Name = fileName, Length = -1
                            };
                            files.Add(fileInfo);
                        }
                        catch (Exception ex)
                        {
                            TLUtils.WriteException("CalculateCacheSizeAsync OpenFile: " + fileName, ex);
                        }
                    }
                }

                _isCalculating = false;

                callback.SafeInvoke(length);

                BeginOnUIThread(() =>
                {
                    Files.Clear();
                    foreach (var file in files)
                    {
                        Files.Add(file);
                    }
                });
            });
        }
Exemplo n.º 4
0
        private void CalculateCacheSizeAsync(Action <long, long> callback)
        {
            BeginOnThreadPool(() =>
            {
                _isCalculating = true;

                var length1 = 0L;
                var length2 = 0L;
                var files   = new List <TelegramFileInfo>();
                _settings.Clear();
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    var fileNames = store.GetFileNames();

                    foreach (var fileName in fileNames)
                    {
                        if (fileName.StartsWith("staticmap"))
                        {
                        }

                        try
                        {
                            var fileInfo = new TelegramFileInfo {
                                Name = fileName
                            };
                            if (store.FileExists(fileName))
                            {
                                using (var file = new IsolatedStorageFileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, store))
                                {
                                    fileInfo.Length = file.Length;
                                    if (IsValidCacheFileName(fileName))
                                    {
                                        if (IsValidPhotoFileName(fileName))
                                        {
                                            _settings.PhotosLength += file.Length;
                                        }
                                        else if (IsValidMusicFileName(fileName))
                                        {
                                            _settings.MusicLength += file.Length;
                                        }
                                        else if (IsValidVideoFileName(fileName))
                                        {
                                            _settings.VideoLength += file.Length;
                                        }
                                        else if (IsValidVoiceMessageFileName(fileName))
                                        {
                                            _settings.VoiceMessagesLength += file.Length;
                                        }
                                        else if (IsValidDocumentFileName(fileName))
                                        {
                                            _settings.DocumentsLength += file.Length;
                                        }
                                        else if (IsValidOtherFileName(fileName))
                                        {
                                            _settings.OtherFilesLength += file.Length;
                                        }

                                        length1 += file.Length;
                                        fileInfo.IsValidCacheFileName = true;
                                    }
                                }
                            }
                            files.Add(fileInfo);
                        }
                        catch (Exception ex)
                        {
                            TLUtils.WriteException("CalculateCacheSizeAsync OpenFile: " + fileName, ex);
                        }
                    }

                    var directoryNames = store.GetDirectoryNames();
                    foreach (var fileName in directoryNames)
                    {
                        try
                        {
                            var fileInfo = new TelegramFileInfo {
                                Name = fileName, Length = -1
                            };
                            files.Add(fileInfo);
                        }
                        catch (Exception ex)
                        {
                            TLUtils.WriteException("CalculateCacheSizeAsync OpenFile: " + fileName, ex);
                        }
                    }

                    length2 = GetDatabaseLength(store, files);
                }

                _isCalculating = false;

                callback.SafeInvoke(length1, length2);

                BeginOnUIThread(() =>
                {
                    Files.Clear();
                    foreach (var file in files)
                    {
                        Files.Add(file);
                    }
                });
            });
        }