/// <summary> /// Imports a CartridgeSavegame from metadata associated to a savegame /// file. /// </summary> /// <param name="gwsFilePath">Path to the GWS savegame file.</param> /// <param name="isf">Isostore file to use to load.</param> /// <returns>The cartridge savegame.</returns> /// public static CartridgeSavegame FromCache(string gwsFilePath, IsolatedStorageFile isf) { // Checks that the metadata file exists. string mdFile = gwsFilePath + ".mf"; if (!(isf.FileExists(mdFile))) { throw new System.IO.FileNotFoundException(mdFile + " does not exist."); } // Creates a serializer. DataContractSerializer serializer = new DataContractSerializer(typeof(CartridgeSavegame)); // Reads the object. CartridgeSavegame cs; using (IsolatedStorageFileStream fs = isf.OpenFile(mdFile, System.IO.FileMode.Open, System.IO.FileAccess.Read)) { // Reads the object. object o = serializer.ReadObject(fs); // Casts it. cs = (CartridgeSavegame)o; } // Adds non-serialized content. cs.SavegameFile = gwsFilePath; cs.MetadataFile = mdFile; // Returns it. return cs; }
public Accelerometro() { InitializeComponent(); accelerometer = new Accelerometer(); accelerometer.TimeBetweenUpdates = TimeSpan.FromMilliseconds(100); accelerometer.Start(); myFile = IsolatedStorageFile.GetUserStoreForApplication(); if (!myFile.FileExists("Impo.txt")) { IsolatedStorageFileStream dataFile = myFile.CreateFile("Impo.txt"); dataFile.Close(); } Wb = new WebBrowser(); Connesso = false; Carica(); System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer(); dt.Interval = new TimeSpan(0, 0, 0, 0, 250); // 500 Milliseconds dt.Tick += new EventHandler(dt_Tick); dt.Start(); }
private void showImage() { if (App.ViewModel.forShare != null) { imagePicker.Content = App.ViewModel.forShare.ItemName; imagePicker.Opacity = 0.5; System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); //点击超链接后图片存在 if (isf.FileExists(App.ViewModel.forShare.ItemName + ".jpg")) { isf.CopyFile(App.ViewModel.forShare.ItemName + ".jpg", "abc.jpg", true); System.IO.IsolatedStorage.IsolatedStorageFileStream PhotoStream = isf.OpenFile("abc.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read); System.Windows.Media.Imaging.BitmapImage bmp1 = new System.Windows.Media.Imaging.BitmapImage(); bmp1.SetSource(PhotoStream); //把文件流转换为图片 PhotoStream.Close(); //读取完毕,关闭文件流 System.Windows.Media.ImageBrush ib = new System.Windows.Media.ImageBrush(); ib.ImageSource = bmp1; tip.Background = ib; //把图片设置为控件的背景图 //imageTip.Visibility = System.Windows.Visibility.Collapsed; } } //如果存在背景,则显示关联按钮 if (tip.Background != null) { appBar3(); } }
/// <summary> /// 读取本地文件信息,SilverLight缓存中 /// </summary> /// <param name="rFileName">存储文件名</param> /// <returns>返回文件数据</returns> public static byte[] ReadSlByteFile(string rFileName) { System.IO.IsolatedStorage.IsolatedStorageFile isf = null; System.IO.Stream stream = null; byte[] buffer = null; try { isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); if (!isf.FileExists(rFileName)) { return(null); } stream = new System.IO.IsolatedStorage.IsolatedStorageFileStream(rFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read, isf); buffer = new byte[stream.Length]; stream.Read(buffer, 0, (int)stream.Length); } finally { if (stream != null) { stream.Close(); // Close the stream stream.Dispose(); } isf.Dispose(); } return(buffer); }
private static void ThrowMappedException(Exception e, string path, IsolatedStorageFile store) { if (store.FileExists(path)) { throw new DatabaseFileLockedException(path, e); } throw new Db4oIOException(e); }
public MainPage() { InitializeComponent(); myFile = IsolatedStorageFile.GetUserStoreForApplication(); if (!myFile.FileExists("Impo.txt")) { IsolatedStorageFileStream dataFile = myFile.CreateFile("Impo.txt"); dataFile.Close(); } }
/// <summary> /// 覆盖基类实现,因为还有硬盘缓存 /// </summary> /// <param name="url"></param> /// <returns></returns> public override bool Contains( string url ) { bool cachedInMem = base.Contains( url ); if ( cachedInMem ) { return true; } else { using ( _storage = IsolatedStorageFile.GetUserStoreForApplication() ) { String filePath = GetFilePath( GetFileName( url ) ); return _storage.FileExists( filePath ); } } }
public static void SafeDeleteFile(IsolatedStorageFile storage, string fileName) { try { if (storage.FileExists(fileName)) { storage.DeleteFile(fileName); } } catch (Exception) { } }
private static void CopyToIsolatedStorage(string file, IsolatedStorageFile store, bool overwrite = true) { if (store.FileExists(file) && !overwrite) return; using (Stream resourceStream = Application.GetResourceStream(new Uri(file, UriKind.Relative)).Stream) using (IsolatedStorageFileStream fileStream = store.OpenFile(file, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) { int bytesRead; var buffer = new byte[resourceStream.Length]; while ((bytesRead = resourceStream.Read(buffer, 0, buffer.Length)) > 0) fileStream.Write(buffer, 0, bytesRead); } }
internal static void ClearSlFiles(string rFileName) { System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); if (rFileName == null || rFileName.TrimEnd() == "") { isf.Remove(); } else { if (isf.FileExists(rFileName)) { isf.DeleteFile(rFileName); } } isf.Dispose(); }
private BitmapImage getThumbnail(string file, IsolatedStorageFile iso) { BitmapImage bmp = new BitmapImage(); if (iso.FileExists(file)) { using (IsolatedStorageFileStream stream = iso.OpenFile(file, FileMode.Open, FileAccess.Read)) { bmp.SetSource(stream); } } else bmp = null; return bmp; }
private ScoreManager() { CurrentScore = 0; BestScore = 0; #if WINDOWS_PHONE savegameStorage = IsolatedStorageFile.GetUserStoreForApplication(); if (savegameStorage.FileExists(filename) == false) { CreateSaveFile(); } else { LoadLastSave(); } #endif }
/// <summary> /// Configures the diagnostic log /// </summary> /// <param name="fileName"></param> /// <param name="enable"> </param> public static void Configure(string fileName, bool enable) { try { _IsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication(); _FileName = fileName; #if DEBUG if (_IsolatedStorage.FileExists(_FileName)) { _IsolatedStorage.DeleteFile(_FileName); } #endif IsEnabled = enable; if (enable) { WriteLogFileHeader(); } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); } }
private void Picture_Save(object sender, EventArgs e) { System.IO.IsolatedStorage.IsolatedStorageFile isf2 = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); // if (isf2.FileExists(imagePicker.Content + ".jpg")) isf2.DeleteFile(imagePicker.Content + ".jpg"); if (isf2.FileExists("abc.jpg")) { isf2.CopyFile("abc.jpg", imagePicker.Content + ".jpg", true); //MessageBox.Show("关联成功"); //takePhote(); if (MessageBox.Show(txtnote.Resources.StringLibrary.chenggong + "!", txtnote.Resources.StringLibrary.guanlian, MessageBoxButton.OKCancel) == MessageBoxResult.OK) { MainPano.DefaultItem = ViewPano; imageTip.Visibility = System.Windows.Visibility.Visible; } } else { MessageBox.Show("Fail!"); } }
private void Delete_Click(object sender, RoutedEventArgs e) { MenuItem clickedLink = (MenuItem)sender; if (clickedLink != null) { ToDoItem toDoForDelete = clickedLink.DataContext as ToDoItem; fileName = toDoForDelete.ItemName; //删除图片 System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); if (isf.FileExists(toDoForDelete.ItemName + ".jpg")) { isf.DeleteFile(toDoForDelete.ItemName + ".jpg"); } //删除磁贴 deleteTile(); // 删除数据 App.ViewModel.DeleteToDoItem(toDoForDelete); } this.Focus(); }
private void showBackground() { System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); //点击超链接后图片存在 if (isf.FileExists("back_temp.jpg")) { System.IO.IsolatedStorage.IsolatedStorageFileStream PhotoStream = isf.OpenFile("back_temp.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read); System.Windows.Media.Imaging.BitmapImage bmp1 = new System.Windows.Media.Imaging.BitmapImage(); bmp1.SetSource(PhotoStream); //把文件流转换为图片 PhotoStream.Close(); //读取完毕,关闭文件流 System.Windows.Media.ImageBrush ib = new System.Windows.Media.ImageBrush(); ib.ImageSource = bmp1; MainPano.Background = ib; //把图片设置为控件的背景图 //imageTip.Visibility = System.Windows.Visibility.Collapsed; } // else // { // MainPano.Background = null; // } }
private static Stream OpenLogFile(IsolatedStorageFile store) { if (Profile == null) { return Stream.Null; } try { var fileName = string.Format(LOGFILE_TEMPLATE, DateTime.UtcNow.ToString("yyyy-MM-dd")); var folderPath = Path.Combine(Profile.CurrentProfilePath(), LOGFOLDER); if (!store.DirectoryExists(folderPath)) { store.CreateDirectory(folderPath); } var filePath = Path.Combine(folderPath, fileName); if (store.FileExists(filePath)) { return store.OpenFile(filePath, FileMode.Append); } else { CleanupLogs(store, folderPath); return store.OpenFile(filePath, FileMode.Create); } } catch (Exception ex) { // Logging Failed, don't kill the process because of it Debugger.Break(); return Stream.Null; } }
void PhotoTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK && e.ChosenPhoto != null) { System.Windows.Media.Imaging.WriteableBitmap bmp = Microsoft.Phone.PictureDecoder.DecodeJpeg(e.ChosenPhoto); System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); if (isf.FileExists("abc.jpg")) { isf.DeleteFile("abc.jpg"); } System.IO.IsolatedStorage.IsolatedStorageFileStream PhotoStream = isf.CreateFile("abc.jpg"); System.Windows.Media.Imaging.Extensions.SaveJpeg(bmp, PhotoStream, 432, 645, 0, 100); //这里设置保存后图片的大小、品质 PhotoStream.Close(); //写入完毕,关闭文件流 PhotoStream = isf.OpenFile("abc.jpg", System.IO.FileMode.Open, System.IO.FileAccess.Read); //读取刚刚保存的图片的文件流 System.Windows.Media.Imaging.BitmapImage bmp1 = new System.Windows.Media.Imaging.BitmapImage(); bmp1.SetSource(PhotoStream); //把文件流转换为图片 PhotoStream.Close(); //读取完毕,关闭文件流 System.Windows.Media.ImageBrush ib = new System.Windows.Media.ImageBrush(); ib.ImageSource = bmp1; tip.Background = ib;//把图片设置为控件的背景图 imageTip.Visibility = System.Windows.Visibility.Collapsed; if (imagePicker.Content.ToString() == txtnote.Resources.StringLibrary.imagename) { if (MessageBox.Show(txtnote.Resources.StringLibrary.imagename, txtnote.Resources.StringLibrary.guanlian, MessageBoxButton.OKCancel) == MessageBoxResult.OK) { NavigationService.Navigate(new Uri("/txtnote;component/Pick.xaml", UriKind.Relative)); } } else { appBar3(); } } }
private void UploadFile() { var updateIe = App.ViewModel.AllToUpdateItems.AsQueryable(); client.UploadCompleted += client_UploadCompleted; System.IO.IsolatedStorage.IsolatedStorageFile isf = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication(); foreach (ToDoItem uploadItem in updateIe) { infoTextBlock.Text = "Uploading..."; byte[] b2 = System.Text.Encoding.UTF8.GetBytes(uploadItem.TxtFile); MemoryStream file = new MemoryStream(b2); //不同difference client.UploadAsync(skyDriveFolderID, uploadItem.ItemName, file, OverwriteOption.Overwrite); string imagename = uploadItem.ItemName + ".jpg"; if (isf.FileExists(imagename)) { System.IO.IsolatedStorage.IsolatedStorageFileStream PhotoStream = isf.OpenFile(imagename, System.IO.FileMode.Open, System.IO.FileAccess.Read); client.UploadAsync(skyDriveFolderID_image, imagename, PhotoStream, OverwriteOption.Overwrite); } } }
private byte[] GetKeyFile(IsolatedStorageFile store) { var path = KeyFilePath; if (!store.FileExists(path)) return null; using (var fs = store.OpenFile(path, FileMode.Open)) { var length = (int)fs.Length; var keyFile = new byte[length]; fs.Read(keyFile, 0, length); return keyFile; } }
public override BitmapSource Load( string url ) { string fileName = GetFileName( url ); BitmapSource retBitmap = null; if ( _memCache.ContainsKey( fileName ) ) { retBitmap = _memCache[fileName]; } if ( retBitmap != null ) { return retBitmap; } // 内存中无缓存 fileName = GetFilePath( GetFileName( url ) ); using ( _storage = IsolatedStorageFile.GetUserStoreForApplication() ) { if ( !_storage.FileExists( fileName ) ) { return BitmapCache.DEFAULT_IMAGE; } BitmapImage bitmap = null; try { IsolatedStorageFileStream fileStream = _storage.OpenFile( fileName, System.IO.FileMode.Open ); Deployment.Current.Dispatcher.BeginInvoke( () => { bitmap = new BitmapImage(); bitmap.SetSource( fileStream ); fileStream.Dispose(); } ); } catch ( Exception e ) { e.ToString(); } return bitmap; } }
/// <summary> /// Determines whether the this database has stored data. /// </summary> /// <param name="store">The store.</param> /// <returns><c>true</c> if this database is valid; otherwise, <c>false</c>. /// </returns> public bool IsValid(IsolatedStorageFile store) { return store.FileExists(InfoPath); }
public override void Store( string url, BitmapSource bitmap ) { Deployment.Current.Dispatcher.BeginInvoke( () => { string fileName = GetFilePath( GetFileName( url ) ); using ( _storage = IsolatedStorageFile.GetUserStoreForApplication() ) { if ( _storage.FileExists( fileName ) ) { _storage.DeleteFile( fileName ); } using ( IsolatedStorageFileStream fileStream = _storage.CreateFile( fileName ) ) { WriteableBitmap writeableBitmap = new WriteableBitmap( bitmap ); writeableBitmap.SaveJpeg( fileStream, writeableBitmap.PixelWidth, writeableBitmap.PixelHeight, 0, IMAGE_QUALITY ); } } } ); }
/// <summary> /// Gets the saved password. /// </summary> /// <returns></returns> private static DbPersistentData GetSavedPassword( IsolatedStorageFile store, string protectPath, string parsedXmlPath, string masterPassPath) { var result = new DbPersistentData(); if (!store.FileExists(protectPath)) { throw new FileNotFoundException(protectPath); } if (!store.FileExists(parsedXmlPath)) { throw new FileNotFoundException(parsedXmlPath); } if (!store.FileExists(masterPassPath)) { throw new FileNotFoundException(masterPassPath); } using (var fs = store.OpenFile(protectPath, FileMode.Open)) using (var buffer = new MemoryStream((int)fs.Length)) { BufferEx.CopyStream(fs, buffer); result.Protection = buffer.ToArray(); } using (var fs = store.OpenFile(parsedXmlPath, FileMode.Open)) using (var buffer = new MemoryStream((int)fs.Length)) { BufferEx.CopyStream(fs, buffer); result.Xml = buffer.ToArray(); } using (var fs = store.OpenFile(masterPassPath, FileMode.Open)) using (var buffer = new MemoryStream((int)fs.Length)) { BufferEx.CopyStream(fs, buffer); result.MasterKey = buffer.ToArray(); } return result; }
/// <summary> /// Changes the name of this savegame. /// </summary> /// <param name="tag"></param> /// <param name="name"></param> public void Rename(CartridgeTag tag, string name, IsolatedStorageFile isf) { string oldGwsFile = SavegameFile; string oldMdFile = MetadataFile; // Changes the properties. Name = name; SetFileProperties(tag); // Renames the files. if (isf.FileExists(oldGwsFile)) { isf.MoveFile(oldGwsFile, SavegameFile); } if (isf.FileExists(oldMdFile)) { isf.MoveFile(oldMdFile, MetadataFile); } }
public bool PingFeed(Uri feeduri, IsolatedStorageFile storage) { return storage.FileExists(feeduri.OriginalString); }
private Snapshot ValidateAndGetSnapshotForFolder(IsolatedStorageFile Iso, string SnapshotDir) { try { DateTime? completionTimeStamp = LoadCompletionTimeStampIfPresent(Iso, SnapshotDir); var settingsPath = Path.Combine(SnapshotDir, SettingsService.SETTINGS_FILE); var settings = Settings.LoadSettingsFromFile(settingsPath); var hasDB = Iso.FileExists(Path.Combine(SnapshotDir, DiversityDataContext.DB_FILENAME)); if (completionTimeStamp.HasValue && settings != null && hasDB) { return SnapshotFromSettingsAndTime(settings, completionTimeStamp.Value, SnapshotDir); } } catch (IsolatedStorageException) { } return null; }
private static DateTime? LoadCompletionTimeStampIfPresent(IsolatedStorageFile Iso, string SnapshotDir) { var completionMarkerPath = Path.Combine(SnapshotDir, COMPLETED_MARKER); var isCompleted = Iso.FileExists(completionMarkerPath); if (isCompleted) { using (var completionFile = Iso.OpenFile(completionMarkerPath, FileMode.Open, FileAccess.Read)) using (var reader = new StreamReader(completionFile)) { var timeString = reader.ReadToEnd(); DateTime readTime; if (DateTime.TryParse(timeString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out readTime)) { return readTime.ToLocalTime(); } } } return null; }
private void GetShowsFromIsolatedStorage() { _isolatedStorage = IsolatedStorageFile.GetUserStoreForAssembly(); if (_isolatedStorage.FileExists(ShowsFileName)) { using (var stream = _isolatedStorage.OpenFile(ShowsFileName, FileMode.Open)) { var deserializer = new BinaryFormatter(); Shows = (ObservableCollection<TvdbSeries>)deserializer.Deserialize(stream); } } else { Shows = new ObservableCollection<TvdbSeries>(); } }
private bool FileExists(string xapFileName, IsolatedStorageFile iso) { return iso.FileExists(xapFileName); }
private void LoadAuth(IsolatedStorageFile isoStore) { if (isoStore.FileExists(AuthFilename)) { try { using (var stream = isoStore.OpenFile(AuthFilename, FileMode.Open, FileAccess.Read)) using (var br = new BinaryReader(stream)) { var fileVer = br.ReadInt32(); var unameLen = br.ReadInt32(); var unameEncrypted = br.ReadBytes(unameLen); var pwordLen = br.ReadInt32(); var pwordEncrypted = br.ReadBytes(pwordLen); var unamePlain = ProtectedData.Unprotect(unameEncrypted, null); var pwordPlain = ProtectedData.Unprotect(pwordEncrypted, null); _username = System.Text.Encoding.UTF8.GetString(unamePlain, 0, unamePlain.Length); _password = System.Text.Encoding.UTF8.GetString(pwordPlain, 0, pwordPlain.Length); IsAuthenticated = true; InitAuth(_username, _password); var numContexts = br.ReadInt32(); Contexts.Clear(); for (int i = 0; i < numContexts; i++) { var usr = new User(); usr.Load(br, fileVer); Contexts.Add(new Context() { User = usr }); } AuthenticatedUser = Contexts[0].User; br.Close(); } } catch (EndOfStreamException) { isoStore.DeleteFile(AuthFilename); } } else { IsAuthenticated = false; } }
private static void DeleteFileHelper(IsolatedStorageFile isoStore, string path) { int retries = 3; while (retries-- > 0) { try { if (isoStore.FileExists(path)) { isoStore.DeleteFile(path); } else { return; } } catch (IsolatedStorageException) { // random iso-store failures.. // Thread.Sleep(50); } return; } }
private static void ExtractFile(IsolatedStorageFile store, string baseFileName) { if (!store.FileExists(baseFileName)) { using (Stream sourceStream = Application.GetResourceStream(new Uri("Data/" + baseFileName, UriKind.Relative)).Stream) { using (IsolatedStorageFileStream targetStream = store.CreateFile(baseFileName)) { byte[] buffer = new byte[1024]; int length; while ((length = sourceStream.Read(buffer, 0, 1024)) > 0) targetStream.Write(buffer, 0, length); targetStream.Close(); } sourceStream.Close(); } } }
private static long GetAvailableSpace(string xapName, IsolatedStorageFile iso) { var availableSpace = iso.AvailableFreeSpace; if (iso.FileExists(xapName)) { using (var file = iso.OpenFile(xapName, FileMode.Open)) { availableSpace += file.Length; } } return availableSpace; }
private void ImportOrMakeSoundsCache(IsolatedStorageFile isf) { _soundFiles = new Dictionary<int, string>(); foreach (var sound in Cartridge.Resources.Where(m => m.Type == MediaType.MP3 || m.Type == MediaType.WAV)) { // Copies the sound file to the cache if it doesn't exist already. string cacheFilename = GetCachePathCore(sound); if (!isf.FileExists(cacheFilename)) { using (IsolatedStorageFileStream fs = isf.CreateFile(cacheFilename)) { fs.Write(sound.Data, 0, sound.Data.Length); } } // Adds the sound filename to the dictionary. _soundFiles.Add(sound.MediaId, cacheFilename); } RaisePropertyChanged("Sounds"); }
private static bool ExistsIn(IsolatedStorageFile storage, string path) { return storage.FileExists(path); }
private String GetFileContentsIfExists(IsolatedStorageFile store, string filename) { String content = null; if (store.FileExists(Path.Combine(Constants.CrashDirectoryName, filename))) { Stream fileStream = store.OpenFile(Path.Combine(Constants.CrashDirectoryName, filename), FileMode.Open); using (StreamReader reader = new StreamReader(fileStream)) { content = reader.ReadToEnd(); } fileStream.Close(); } return content; }
private void LoadRepos(IsolatedStorageFile iso) { if (!iso.FileExists(RepoFilename)) return; try { using (var stream = iso.OpenFile(RepoFilename, FileMode.Open, FileAccess.Read)) using (var br = new BinaryReader(stream)) { var fileVer = br.ReadInt32(); var numContexts = br.ReadInt32(); for (int i = 0; i < numContexts; i++) { var login = br.ReadString(); foreach (var context in Contexts) { if (context.User.Login.Equals(login)) { var numMyRepos = br.ReadInt32(); context.Repositories.Clear(); for (int j = 0; j < numMyRepos; j++) { var repo = new Repo(); repo.Load(br, fileVer); context.Repositories.Add(repo); } break; } } } br.Close(); } } catch (EndOfStreamException) { iso.DeleteFile(RepoFilename); } }
public override Task <bool> GetFileExistsAsync(string path) { return(Task <bool> .Factory.StartNew(() => file.FileExists(path))); }