private static void CreateDirectory(string targetFileName) { string directory = FileManager.GetDirectory(targetFileName); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } }
public static bool FileExists(string fileName, bool ignoreExtensions) { if (!ignoreExtensions) { #if ANDROID try { fileName = Standardize(fileName); if (fileName.StartsWith(".\\")) { fileName = fileName.Substring(2); } using (var stream = Microsoft.Xna.Framework.TitleContainer.OpenStream(fileName)) { return(stream != null); } } catch { return(false); } #else return(File.Exists(fileName)); #endif } else { fileName = Standardize(fileName); // This takes a little bit of work string fileWithoutExtension = FileManager.RemoveExtension(fileName); List <string> filesInDirectory = GetAllFilesInDirectory( FileManager.GetDirectory(fileName), null, 0); for (int i = 0; i < filesInDirectory.Count; i++) { if (filesInDirectory[i] == fileName || FileManager.RemoveExtension(filesInDirectory[i]) == fileWithoutExtension) { return(true); } } return(false); } }
public static void SaveByteArray(byte[] whatToSave, string fileName) { if (FileManager.FileExists(fileName)) { File.Delete(fileName); } Directory.CreateDirectory(FileManager.GetDirectory(fileName)); using (FileStream fs = new FileStream(fileName, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { bw.Write(whatToSave); bw.Close(); fs.Close(); } } }
private void HandleWireframePropertyChanged(object sender, PropertyChangedEventArgs e) { switch (e.PropertyName) { case nameof(WireframeEditControlsViewModel.SelectedTextureFilePath): RecordCameraPosition(); // update the texture before updating the frame (and calling refresh) UpdateToSelectedAnimationTextureFile(WireframeEditControlsViewModel.SelectedTextureFilePath); UpdateToSavedCameraPosition(); if (SelectedState.Self.SelectedFrame != null && WireframeEditControlsViewModel.SelectedTextureFilePath != null) { var achxFolder = FileManager.GetDirectory(SelectedState.Self.SelectedChain.Name); achxFolder = FileManager.GetDirectory(ProjectManager.Self.FileName); string relativeFileName = FileManager.MakeRelative(WireframeEditControlsViewModel.SelectedTextureFilePath.FullPath, achxFolder); SelectedState.Self.SelectedFrame.TextureName = relativeFileName; AnimationFrameChange?.Invoke(this, null); PropertyGridManager.Self.Refresh(); RefreshAll(); } break; case nameof(WireframeEditControlsViewModel.IsMagicWandSelected): ReactToMagicWandChange(this, null); break; case nameof(WireframeEditControlsViewModel.IsSnapToGridChecked): ReactToSnapToGridChecedChange(); break; } }
public static string FindAndAddExtension(string fileName) { fileName = Standardize(fileName); // This takes a little bit of work string fileWithoutExtension = FileManager.RemoveExtension(fileName); List <string> filesInDirectory = GetAllFilesInDirectory( FileManager.GetDirectory(fileName), null, 0); for (int i = 0; i < filesInDirectory.Count; i++) { if (filesInDirectory[i] == fileName || FileManager.RemoveExtension(filesInDirectory[i]) == fileWithoutExtension) { return(filesInDirectory[i]); } } return(fileName); }
public static void XmlSerialize(Type type, object objectToSerialize, string fileName) { FileStream fs = null; #if SILVERLIGHT IsolatedStorageFileStream isfs = null; XmlWriter writer = null; #endif try { // Make sure that the directory for the file settings exist string directory = FileManager.GetDirectory(fileName); if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory)) { Directory.CreateDirectory(FileManager.GetDirectory(fileName)); } XmlSerializer serializer = GetXmlSerializer(type); #if SILVERLIGHT if (!fileName.Contains(IsolatedStoragePrefix)) { throw new ArgumentException("In Silverlight you must use isolated storage. Use FileManager.GetUserFolder."); } string modifiedFileName = GetIsolatedStorageFileName(fileName); isfs = new IsolatedStorageFileStream( modifiedFileName, FileMode.Create, mIsolatedStorageFile); XmlWriterSettings xms = new XmlWriterSettings(); xms.Encoding = System.Text.Encoding.UTF8; xms.Indent = true; writer = XmlWriter.Create(isfs, xms); #else if (FileManager.FileExists(fileName)) { fs = System.IO.File.Open(fileName, FileMode.OpenOrCreate | FileMode.Truncate); } else { fs = System.IO.File.Open(fileName, FileMode.OpenOrCreate); } XmlTextWriter writer = new XmlTextWriter(fs, System.Text.Encoding.UTF8); writer.Formatting = System.Xml.Formatting.Indented; #endif serializer.Serialize(writer, objectToSerialize); } finally { if (fs != null) { fs.Close(); } #if SILVERLIGHT if (isfs != null) { isfs.Close(); } #endif } }
public FilePath GetDirectoryContainingThis() { return(FileManager.GetDirectory(this.StandardizedCaseSensitive)); }