private GetFullPath ( string partialPath ) : string | ||
partialPath | string | |
리턴 | string |
// If the isolated storage file is null, then we default to using a file // that is scoped by user, appdomain, and assembly. public IsolatedStorageFileStream(String path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile isf) { if (path == null) { throw new ArgumentNullException(nameof(path)); } Contract.EndContractBlock(); if ((path.Length == 0) || path.Equals(s_BackSlash)) { throw new ArgumentException( SR.IsolatedStorage_Path); } if (isf == null) { throw new ArgumentNullException(nameof(isf)); } if (isf.Disposed) { throw new ObjectDisposedException(null, SR.IsolatedStorage_StoreNotOpen); } switch (mode) { case FileMode.CreateNew: // Assume new file case FileMode.Create: // Check for New file & Unreserve case FileMode.OpenOrCreate: // Check for new file case FileMode.Truncate: // Unreserve old file size case FileMode.Append: // Check for new file case FileMode.Open: // Open existing, else exception break; default: throw new ArgumentException(SR.IsolatedStorage_FileOpenMode); } _isf = isf; _givenPath = path; _fullPath = _isf.GetFullPath(_givenPath); try { _fs = new FileStream(_fullPath, mode, access, share, bufferSize, FileOptions.None); } catch (Exception e) { // Exception message might leak the IsolatedStorage path. The desktop prevented this by calling an // internal API which made sure that the exception message was scrubbed. However since the innerException // is never returned to the user(GetIsolatedStorageException() does not populate the innerexception // in retail bits we leak the path only under the debugger via IsolatedStorageException._underlyingException which // they can any way look at via IsolatedStorageFile instance as well. throw IsolatedStorageFile.GetIsolatedStorageException("IsolatedStorage_Operation_ISFS", e); } }
private long GetFileSize(IsolatedStorageFile store, string path) { string fullPath = store.GetFullPath(path); try { if (File.Exists(fullPath)) return new System.IO.FileInfo(fullPath).Length; } catch (IOException ex) { System.Diagnostics.Trace.WriteLine("Exceptionless: Error getting size of file: {0}", ex.Message); } return -1; }
// If the isolated storage file is null, then we default to using a file // that is scoped by user, appdomain, and assembly. public IsolatedStorageFileStream(String path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile isf) { if (path == null) throw new ArgumentNullException("path"); Contract.EndContractBlock(); if ((path.Length == 0) || path.Equals(s_BackSlash)) throw new ArgumentException( SR.IsolatedStorage_Path); if (isf == null) { throw new ArgumentNullException("isf"); } if (isf.Disposed) throw new ObjectDisposedException(null, SR.IsolatedStorage_StoreNotOpen); switch (mode) { case FileMode.CreateNew: // Assume new file case FileMode.Create: // Check for New file & Unreserve case FileMode.OpenOrCreate: // Check for new file case FileMode.Truncate: // Unreserve old file size case FileMode.Append: // Check for new file case FileMode.Open: // Open existing, else exception break; default: throw new ArgumentException(SR.IsolatedStorage_FileOpenMode); } _isf = isf; _givenPath = path; _fullPath = _isf.GetFullPath(_givenPath); try { _fs = new FileStream(_fullPath, mode, access, share, bufferSize, FileOptions.None); } catch (Exception e) { // Exception message might leak the IsolatedStorage path. The desktop prevented this by calling an // internal API which made sure that the exception message was scrubbed. However since the innerException // is never returned to the user(GetIsolatedStorageException() does not populate the innerexception // in retail bits we leak the path only under the debugger via IsolatedStorageException._underlyingException which // they can any way look at via IsolatedStorageFile instance as well. throw IsolatedStorageFile.GetIsolatedStorageException("IsolatedStorage_Operation_ISFS", e); } }
// If IsolatedStorageFile is null, then we default to using a file that is scoped by user, appdomain, and assembly. private static InitialiationData InitializeFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile isf) { if (path == null) throw new ArgumentNullException(nameof(path)); if ((path.Length == 0) || path.Equals(BackSlash)) throw new ArgumentException( SR.IsolatedStorage_Path); bool createdStore = false; if (isf == null) { isf = IsolatedStorageFile.GetUserStoreForDomain(); createdStore = true; } if (isf.Disposed) throw new ObjectDisposedException(null, SR.IsolatedStorage_StoreNotOpen); switch (mode) { case FileMode.CreateNew: // Assume new file case FileMode.Create: // Check for New file & Unreserve case FileMode.OpenOrCreate: // Check for new file case FileMode.Truncate: // Unreserve old file size case FileMode.Append: // Check for new file case FileMode.Open: // Open existing, else exception break; default: throw new ArgumentException(SR.IsolatedStorage_FileOpenMode); } InitialiationData data = new InitialiationData { FullPath = isf.GetFullPath(path), StorageFile = isf }; try { data.NestedStream = new FileStream(data.FullPath, mode, access, share, bufferSize, FileOptions.None); } catch (Exception e) { // Make an attempt to clean up the StorageFile if we created it try { if (createdStore) { data.StorageFile?.Dispose(); } } catch { } // Exception message might leak the IsolatedStorage path. The desktop prevented this by calling an // internal API which made sure that the exception message was scrubbed. However since the innerException // is never returned to the user(GetIsolatedStorageException() does not populate the innerexception // in retail bits we leak the path only under the debugger via IsolatedStorageException._underlyingException which // they can any way look at via IsolatedStorageFile instance as well. throw IsolatedStorageFile.GetIsolatedStorageException(SR.IsolatedStorage_Operation_ISFS, e); } return data; }
public IsolatedStorageFileStream(String path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile isf) { if (path == null) throw new ArgumentNullException("path"); Contract.EndContractBlock(); #if FEATURE_PAL if (s_BackSlash == null) s_BackSlash = new String(System.IO.Path.DirectorySeparatorChar,1); #endif // FEATURE_PAL if ((path.Length == 0) || path.Equals(s_BackSlash)) throw new ArgumentException( Environment.GetResourceString( "IsolatedStorage_Path")); ulong oldFileSize=0, newFileSize; bool fNewFile = false, fLock=false; if (isf == null) { #if FEATURE_ISOSTORE_LIGHT throw new ArgumentNullException("isf"); #else // !FEATURE_ISOSTORE_LIGHT m_OwnedStore = true; isf = IsolatedStorageFile.GetUserStoreForDomain(); #endif // !FEATURE_ISOSTORE_LIGHT } if (isf.Disposed) throw new ObjectDisposedException(null, Environment.GetResourceString("IsolatedStorage_StoreNotOpen")); m_isf = isf; FileIOPermission fiop = new FileIOPermission(FileIOPermissionAccess.AllAccess, m_isf.RootDirectory); fiop.Assert(); fiop.PermitOnly(); m_GivenPath = path; m_FullPath = m_isf.GetFullPath(m_GivenPath); RuntimeHelpers.PrepareConstrainedRegions(); try { // for finally Unlocking locked store // Cache the old file size if the file size could change // Also find if we are going to create a new file. switch (mode) { case FileMode.CreateNew: // Assume new file #if FEATURE_ISOSTORE_LIGHT // We are going to call Reserve so we need to lock the store. m_isf.Lock(ref fLock); #endif fNewFile = true; break; case FileMode.Create: // Check for New file & Unreserve case FileMode.OpenOrCreate: // Check for new file case FileMode.Truncate: // Unreserve old file size case FileMode.Append: // Check for new file m_isf.Lock(ref fLock); // oldFileSize needs to be // protected try { #if FEATURE_ISOSTORE_LIGHT oldFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)(new FileInfo(m_FullPath).Length)); #else oldFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)LongPathFile.GetLength(m_FullPath)); #endif } catch (FileNotFoundException) { fNewFile = true; } catch { } break; case FileMode.Open: // Open existing, else exception break; default: throw new ArgumentException( Environment.GetResourceString( "IsolatedStorage_FileOpenMode")); } if (fNewFile) m_isf.ReserveOneBlock(); try { #if FEATURE_ISOSTORE_LIGHT m_fs = new FileStream(m_FullPath, mode, access, share, bufferSize, FileOptions.None, m_GivenPath, true); #else m_fs = new FileStream(m_FullPath, mode, access, share, bufferSize, FileOptions.None, m_GivenPath, true, true); #endif } catch { if (fNewFile) m_isf.UnreserveOneBlock(); #if FEATURE_ISOSTORE_LIGHT // IsoStore generally does not let arbitrary exceptions flow out: a // IsolatedStorageException is thrown instead (see examples in IsolatedStorageFile.cs // Keeping this scoped to coreclr just because changing the exception type thrown is a // breaking change and that should not be introduced into the desktop without deliberation. throw new IsolatedStorageException(Environment.GetResourceString("IsolatedStorage_Operation_ISFS")); #else throw; #endif // FEATURE_ISOSTORE_LIGHT } // make adjustment to the Reserve / Unreserve state if ((fNewFile == false) && ((mode == FileMode.Truncate) || (mode == FileMode.Create))) { newFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)m_fs.Length); if (oldFileSize > newFileSize) m_isf.Unreserve(oldFileSize - newFileSize); else if (newFileSize > oldFileSize) // Can this happen ? m_isf.Reserve(newFileSize - oldFileSize); } } finally { if (fLock) m_isf.Unlock(); } CodeAccessPermission.RevertAll(); }
// If IsolatedStorageFile is null, then we default to using a file that is scoped by user, appdomain, and assembly. private static InitialiationData InitializeFileStream(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile isf) { if (path == null) { throw new ArgumentNullException(nameof(path)); } if ((path.Length == 0) || path.Equals(BackSlash)) { throw new ArgumentException( SR.IsolatedStorage_Path); } bool createdStore = false; if (isf == null) { isf = IsolatedStorageFile.GetUserStoreForDomain(); createdStore = true; } if (isf.Disposed) { throw new ObjectDisposedException(null, SR.IsolatedStorage_StoreNotOpen); } switch (mode) { case FileMode.CreateNew: // Assume new file case FileMode.Create: // Check for New file & Unreserve case FileMode.OpenOrCreate: // Check for new file case FileMode.Truncate: // Unreserve old file size case FileMode.Append: // Check for new file case FileMode.Open: // Open existing, else exception break; default: throw new ArgumentException(SR.IsolatedStorage_FileOpenMode); } InitialiationData data = new InitialiationData { FullPath = isf.GetFullPath(path), StorageFile = isf }; try { data.NestedStream = new FileStream(data.FullPath, mode, access, share, bufferSize, FileOptions.None); } catch (Exception e) { // Make an attempt to clean up the StorageFile if we created it try { if (createdStore) { data.StorageFile?.Dispose(); } } catch { } // Exception message might leak the IsolatedStorage path. The desktop prevented this by calling an // internal API which made sure that the exception message was scrubbed. However since the innerException // is never returned to the user(GetIsolatedStorageException() does not populate the innerexception // in retail bits we leak the path only under the debugger via IsolatedStorageException._underlyingException which // they can any way look at via IsolatedStorageFile instance as well. throw IsolatedStorageFile.GetIsolatedStorageException(SR.IsolatedStorage_Operation_ISFS, e); } return(data); }
[System.Security.SecuritySafeCritical] // auto-generated public IsolatedStorageFileStream(String path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile isf) { if (path == null) { throw new ArgumentNullException("path"); } Contract.EndContractBlock(); #if FEATURE_PAL if (s_BackSlash == null) { s_BackSlash = new String(System.IO.Path.DirectorySeparatorChar, 1); } #endif // FEATURE_PAL if ((path.Length == 0) || path.Equals(s_BackSlash)) { throw new ArgumentException( Environment.GetResourceString( "IsolatedStorage_Path")); } if (isf == null) { #if FEATURE_ISOSTORE_LIGHT throw new ArgumentNullException("isf"); #else // !FEATURE_ISOSTORE_LIGHT m_OwnedStore = true; isf = IsolatedStorageFile.GetUserStoreForDomain(); #endif // !FEATURE_ISOSTORE_LIGHT } if (isf.Disposed) { throw new ObjectDisposedException(null, Environment.GetResourceString("IsolatedStorage_StoreNotOpen")); } switch (mode) { case FileMode.CreateNew: // Assume new file case FileMode.Create: // Check for New file & Unreserve case FileMode.OpenOrCreate: // Check for new file case FileMode.Truncate: // Unreserve old file size case FileMode.Append: // Check for new file case FileMode.Open: // Open existing, else exception break; default: throw new ArgumentException(Environment.GetResourceString("IsolatedStorage_FileOpenMode")); } m_isf = isf; #if !FEATURE_CORECLR FileIOPermission fiop = new FileIOPermission(FileIOPermissionAccess.AllAccess, m_isf.RootDirectory); fiop.Assert(); fiop.PermitOnly(); #endif m_GivenPath = path; m_FullPath = m_isf.GetFullPath(m_GivenPath); #if FEATURE_ISOLATED_STORAGE_QUOTA_ENFORCEMENT ulong oldFileSize = 0, newFileSize; bool fNewFile = false, fLock = false; RuntimeHelpers.PrepareConstrainedRegions(); try { // for finally Unlocking locked store // Cache the old file size if the file size could change // Also find if we are going to create a new file. switch (mode) { case FileMode.CreateNew: // Assume new file #if FEATURE_ISOSTORE_LIGHT // We are going to call Reserve so we need to lock the store. m_isf.Lock(ref fLock); #endif fNewFile = true; break; case FileMode.Create: // Check for New file & Unreserve case FileMode.OpenOrCreate: // Check for new file case FileMode.Truncate: // Unreserve old file size case FileMode.Append: // Check for new file m_isf.Lock(ref fLock); // oldFileSize needs to be // protected try { #if FEATURE_ISOSTORE_LIGHT oldFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)(FileInfo.UnsafeCreateFileInfo(m_FullPath).Length)); #else oldFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)LongPathFile.GetLength(m_FullPath)); #endif } catch (FileNotFoundException) { fNewFile = true; } catch { } break; case FileMode.Open: // Open existing, else exception break; } if (fNewFile) { m_isf.ReserveOneBlock(); } #endif // FEATURE_ISOLATED_STORAGE_QUOTA_ENFORCEMENT try { #if FEATURE_CORECLR // Since FileStream's .ctor won't do a demand, we need to do our access check here. m_isf.Demand(m_FullPath); #endif #if FEATURE_ISOSTORE_LIGHT m_fs = new FileStream(m_FullPath, mode, access, share, bufferSize, FileOptions.None, m_GivenPath, true); } catch (Exception e) { #else m_fs = new FileStream(m_FullPath, mode, access, share, bufferSize, FileOptions.None, m_GivenPath, true, true); } catch { #endif #if FEATURE_ISOLATED_STORAGE_QUOTA_ENFORCEMENT if (fNewFile) { m_isf.UnreserveOneBlock(); } #endif // FEATURE_ISOLATED_STORAGE_QUOTA_ENFORCEMENT #if FEATURE_ISOSTORE_LIGHT // IsoStore generally does not let arbitrary exceptions flow out: a // IsolatedStorageException is thrown instead (see examples in IsolatedStorageFile.cs // Keeping this scoped to coreclr just because changing the exception type thrown is a // breaking change and that should not be introduced into the desktop without deliberation. // // Note that GetIsolatedStorageException may set InnerException. To the real exception // Today it always does this, for debug and chk builds, and for other builds asks the host // if it is okay to do so. throw IsolatedStorageFile.GetIsolatedStorageException("IsolatedStorage_Operation_ISFS", e); #else throw; #endif // FEATURE_ISOSTORE_LIGHT } #if FEATURE_ISOLATED_STORAGE_QUOTA_ENFORCEMENT // make adjustment to the Reserve / Unreserve state if ((fNewFile == false) && ((mode == FileMode.Truncate) || (mode == FileMode.Create))) { newFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)m_fs.Length); if (oldFileSize > newFileSize) { m_isf.Unreserve(oldFileSize - newFileSize); } else if (newFileSize > oldFileSize) // Can this happen ? { m_isf.Reserve(newFileSize - oldFileSize); } } } finally { if (fLock) { m_isf.Unlock(); } } #endif // FEATURE_ISOLATED_STORAGE_QUOTA_ENFORCEMENT #if !FEATURE_CORECLR CodeAccessPermission.RevertAll(); #endif }
/// <include file='doc\IsolatedStorageFileStream.uex' path='docs/doc[@for="IsolatedStorageFileStream.IsolatedStorageFileStream7"]/*' /> public IsolatedStorageFileStream(String path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile isf) { if (path == null) throw new ArgumentNullException("path"); if (s_BackSlash == null) s_BackSlash = new String(System.IO.Path.DirectorySeparatorChar,1); if ((path.Length == 0) || path.Equals(s_BackSlash)) throw new ArgumentException( Environment.GetResourceString( "IsolatedStorage_path")); ulong oldFileSize=0, newFileSize; bool fNewFile = false; FileInfo fOld; if (isf == null) { m_OwnedStore = true; isf = IsolatedStorageFile.GetUserStoreForDomain(); } m_isf = isf; FileIOPermission fiop = new FileIOPermission(FileIOPermissionAccess.AllAccess, m_isf.RootDirectory); fiop.Assert(); m_GivenPath = path; m_FullPath = m_isf.GetFullPath(m_GivenPath); // Cache the old file size if the file size could change // Also find if we are going to create a new file. switch (mode) { case FileMode.CreateNew: // Assume new file fNewFile = true; break; case FileMode.Create: // Check for New file & Unreserve case FileMode.OpenOrCreate: // Check for new file case FileMode.Truncate: // Unreserve old file size case FileMode.Append: // Check for new file try { fOld = new FileInfo(m_FullPath); oldFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)fOld.Length); } catch (Exception e) { if (e is FileNotFoundException) fNewFile = true; } break; case FileMode.Open: // Open existing, else exception break; default: throw new ArgumentException( Environment.GetResourceString( "IsolatedStorage_FileOpenMode")); } if (fNewFile) m_isf.ReserveOneBlock(); try { m_fs = new FileStream(m_FullPath, mode, access, share, bufferSize, false, m_GivenPath, true); } catch (Exception) { if (fNewFile) m_isf.UnreserveOneBlock(); throw; } // make adjustment to the Reserve / Unreserve state if ((fNewFile == false) && ((mode == FileMode.Truncate) || (mode == FileMode.Create))) { newFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)m_fs.Length); if (oldFileSize > newFileSize) m_isf.Unreserve(oldFileSize - newFileSize); else if (newFileSize > oldFileSize) // Can this happen ? m_isf.Reserve(newFileSize - oldFileSize); } }
public IsolatedStorageFileStream(String path, FileMode mode, FileAccess access, FileShare share, int bufferSize, IsolatedStorageFile isf) { if (path == null) { throw new ArgumentNullException("path"); } if (s_BackSlash == null) { s_BackSlash = new String(System.IO.Path.DirectorySeparatorChar, 1); } if ((path.Length == 0) || path.Equals(s_BackSlash)) { throw new ArgumentException( Environment.GetResourceString( "IsolatedStorage_path")); } ulong oldFileSize = 0, newFileSize; bool fNewFile = false, fLock = false; FileInfo fOld; if (isf == null) { m_OwnedStore = true; isf = IsolatedStorageFile.GetUserStoreForDomain(); } m_isf = isf; FileIOPermission fiop = new FileIOPermission(FileIOPermissionAccess.AllAccess, m_isf.RootDirectory); fiop.Assert(); fiop.PermitOnly(); m_GivenPath = path; m_FullPath = m_isf.GetFullPath(m_GivenPath); try { // for finally Unlocking locked store // Cache the old file size if the file size could change // Also find if we are going to create a new file. switch (mode) { case FileMode.CreateNew: // Assume new file fNewFile = true; break; case FileMode.Create: // Check for New file & Unreserve case FileMode.OpenOrCreate: // Check for new file case FileMode.Truncate: // Unreserve old file size case FileMode.Append: // Check for new file m_isf.Lock(); // oldFileSize needs to be // protected fLock = true; // Lock succeded try { fOld = new FileInfo(m_FullPath); oldFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)fOld.Length); } catch (FileNotFoundException) { fNewFile = true; } catch { } break; case FileMode.Open: // Open existing, else exception break; default: throw new ArgumentException( Environment.GetResourceString( "IsolatedStorage_FileOpenMode")); } if (fNewFile) { m_isf.ReserveOneBlock(); } try { m_fs = new FileStream(m_FullPath, mode, access, share, bufferSize, FileOptions.None, m_GivenPath, true); } catch { if (fNewFile) { m_isf.UnreserveOneBlock(); } throw; } // make adjustment to the Reserve / Unreserve state if ((fNewFile == false) && ((mode == FileMode.Truncate) || (mode == FileMode.Create))) { newFileSize = IsolatedStorageFile.RoundToBlockSize((ulong)m_fs.Length); if (oldFileSize > newFileSize) { m_isf.Unreserve(oldFileSize - newFileSize); } else if (newFileSize > oldFileSize) // Can this happen ? { m_isf.Reserve(newFileSize - oldFileSize); } } } finally { if (fLock) { m_isf.Unlock(); } } CodeAccessPermission.RevertAll(); }