private void CreateButtons() { #if UNITY_STANDALONE var directories = new List <IO.DirectoryInfo>(); var currentPath = text; var cdir = new IO.DirectoryInfo(currentPath); directories.Add(cdir); var count = 0; while (count < 30) { try { var dir = System.IO.Directory.GetParent(currentPath); if (dir == null) { break; } directories.Add(dir); currentPath = dir.FullName; } catch (Exception) { // Fix: nullreference?? (Directory.GetParent("C:\\")). } count++; } var allowedWidth = Width; float currentWidth = 0; int currentIndex; for (currentIndex = 0; currentIndex < directories.Count; currentIndex++) { var dir = directories[currentIndex]; var estimatedWidth = Font.MeasureStringSimple(dir.Name).Width + 15; currentWidth += estimatedWidth; if (currentWidth >= allowedWidth) { break; } var button = new pathButton(dir.FullName); button.Height = Height - 2; button.Width = (int)estimatedWidth; button.Text = dir.Name; button.Click += (sender, args) => fileDialog.fileRenderer.SetDirectory(button.Path, true); Controls.Add(button); } updateButtons = true; #endif }
public static void UnZip(string fileName) { ZipStorer zip = ZipStorer.Open(fileName, IO.FileAccess.Read); List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir(); IO.FileInfo fi = new IO.FileInfo(fileName); IO.DirectoryInfo di = new IO.DirectoryInfo(fi.FullName.Replace(fi.Extension, "")); if (!di.Exists) { di.Create(); } foreach (ZipStorer.ZipFileEntry entry in dir) { zip.ExtractFile(entry, IO.Path.Combine(di.FullName, entry.FilenameInZip)); } zip.Close(); }
protected override void LoadSystemFonts() { if (m_LoadSystemFonts_CalledOnce) { return; } m_LoadSystemFonts_CalledOnce = true; FontFamily[] families = new InstalledFontCollection().Families; if (families != null && families.Length > 0) { return; } #if PORTABLE || SILVERLIGHT string[] names = Enum.GetNames(typeof(System.Environment.SpecialFolder)); foreach (string name in names) { if (string.Compare(name, "Fonts") == 0) { base.LoadSystemFonts(); return; } } #endif String fontsDir = null; #if !WINDOWS_PHONE && !WINDOWS_PHONE_7 && !WINDOWS_PHONE_71 #if NET40 || ANDROID || __IOS__ // NET40 or higher fontsDir = Environment.GetFolderPath(Environment.SpecialFolder.Fonts); #else #if SILVERLIGHT && !WINDOWS_PHONE && !WINDOWS_PHONE_7 && !WINDOWS_PHONE_71 try { fontsDir = Environment.GetFolderPath(Environment.SpecialFolder.System); // get parent of System folder to have Windows folder IO.DirectoryInfo dirWindowsFolder = new IO.DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.System)); // Concatenate Fonts folder onto Windows folder. fontsDir = IO.Path.Combine(dirWindowsFolder.Parent.FullName, "Fonts"); } catch { fontsDir = null; } #else PlatformID pid = Environment.OSVersion.Platform; if (pid == PlatformID.Win32NT) { // get parent of System folder to have Windows folder IO.DirectoryInfo dirWindowsFolder = IO.Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.System)); if (dirWindowsFolder != null) { // Concatenate Fonts folder onto Windows folder. fontsDir = IO.Path.Combine(dirWindowsFolder.FullName, "Fonts"); } } else if (pid == PlatformID.Unix) { //Path.Combine(home, ".fonts"); fontsDir = "usr/share/fonts/truetype"; } #if !WINDOWS_PHONE && !WINDOWS_PHONE_7 && !WINDOWS_PHONE_71 else if (pid == PlatformID.MacOSX) { // Path.Combine(home, "Library", "Fonts"); fontsDir = "Library/Fonts"; } #endif #endif #endif #endif if (!string.IsNullOrEmpty(fontsDir) && IO.Directory.Exists(fontsDir)) { InstalledFontCollection.LoadCache(); { try { InstalledFontCollection.AddFontFiles(fontsDir, true); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } InstalledFontCollection.SaveCache(); } // Load additional font files (if no any system fonts loaded) and set default params //??? if ((new InstalledFontCollection()).Families.Length == 0) { #if SILVERLIGHT || WINDOWS_PHONE || WINDOWS_PHONE_7 || WINDOWS_PHONE_71 || ANDROID || __IOS__ Alt.Sketch.Config.Font_NoAntiAliasMaxSize = 5; #endif InstalledFontCollection.AddFontFiles("AltData/Fonts"); InstalledFontCollection.AddFontFiles("AltData/Fonts/Open-Sans"); } }