Commit d5afd98
Fix the drive letter bug on Windows
Changed files (12)
modifiedlibbirdfont/BackgroundImage.valamodifiedlibbirdfont/BirdFont.valamodifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/BirdFontPart.valamodifiedlibbirdfont/CutBackgroundTool.valamodifiedlibbirdfont/ExportTool.valamodifiedlibbirdfont/FileDialogTab.valamodifiedlibbirdfont/FileTab.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/Preferences.valamodifiedlibbirdfont/Preview.valamodifiedlibbirdfont/TestCases.vala
Diff
@@ -233,7 +233,7 @@ public class BackgroundImage { DirUtils.create ((!) dir.get_path (), 0755); } - dir = font.get_backgrounds_folder ().get_child ("parts");+ dir = get_child (font.get_backgrounds_folder (), "parts"); if (!dir.query_exists ()) { DirUtils.create ((!) dir.get_path (), 0755); }@@ -314,7 +314,7 @@ public class BackgroundImage { Font font = BirdFont.get_current_font (); File folder = font.get_backgrounds_folder (); File original = File.new_for_path (file_name);- File png_image = folder.get_child (@"full_$((!)original.get_basename ())");+ File png_image = get_child (folder, @"full_$((!)original.get_basename ())"); bool converted; if (png_image.query_exists ()) {@@ -533,7 +533,7 @@ public class BirdFont { public static File get_preview_directory () { File settings = get_settings_directory ();- File backup = settings.get_child ("preview");+ File backup = get_child(settings, "preview"); if (!backup.query_exists ()) { DirUtils.create ((!) backup.get_path (), 0755);@@ -543,7 +543,7 @@ public class BirdFont { } internal static File get_thumbnail_directory () {- File thumbnails = get_settings_directory ().get_child ("thumbnails");+ File thumbnails = get_child (get_settings_directory (), "thumbnails"); if (!thumbnails.query_exists ()) { DirUtils.create ((!) thumbnails.get_path (), 0755);@@ -576,7 +576,7 @@ public class BirdFont { home = File.new_for_path (home_path); #endif- settings = home.get_child ("birdfont");+ settings = get_child(home, "birdfont"); if (!settings.query_exists ()) { DirUtils.create ((!) settings.get_path (), 0755);@@ -587,7 +587,7 @@ public class BirdFont { internal static File get_backup_directory () { File settings = get_settings_directory ();- File backup = settings.get_child ("backup");+ File backup = get_child (settings, "backup"); if (!backup.query_exists ()) { DirUtils.create ((!) backup.get_path (), 0755);@@ -619,7 +619,7 @@ void init_logfile () { t = new DateTime.now_local (); settings = BirdFont.get_settings_directory (); s = t.to_string ().replace (":", "_");- log = settings.get_child (@"birdfont_$s.log");+ log = get_child (settings, @"birdfont_$s.log"); BirdFont.logstream = new DataOutputStream (log.create (FileCreateFlags.REPLACE_DESTINATION)); ((!)BirdFont.logstream).put_string ((!) log.get_path ());@@ -685,3 +685,28 @@ public static void warn_if_test (string message) { } } +/** Obtain a handle to a file in a folder. */ +public static File get_child (File folder, string file_name) {+ string f;+ string s;+ string n;++ // avoid drive letter problems on windows+ + n = file_name;+ if (unlikely (BirdFont.win32 && file_name.index_of ("\\") != -1)) {+ warning ("File name contains path separator.");+ n = n.substring (n.last_index_of ("\\")).replace ("\\", "");+ }+ + f = (!) folder.get_path ();+ s = (BirdFont.win32) ? "\\" : "/"; + + if (!f.has_suffix (s)) {+ f += s;+ }+ + return File.new_for_path (f + n);+}++}@@ -796,13 +796,13 @@ class BirdFontFile : GLib.Object { DirUtils.create ((!) font.get_backgrounds_folder ().get_path (), 0755); } - img_dir = font.get_backgrounds_folder ().get_child ("parts");+ img_dir = get_child (font.get_backgrounds_folder (), "parts"); if (!img_dir.query_exists ()) { DirUtils.create ((!) img_dir.get_path (), 0755); } - img_file = img_dir.get_child (@"$(file).png");+ img_file = get_child (img_dir, @"$(file).png"); if (img_file.query_exists ()) { return;@@ -1310,11 +1310,11 @@ class BirdFontFile : GLib.Object { BackgroundImage img; BackgroundImage? new_img = null; - File img_file = font.get_backgrounds_folder ().get_child ("parts");+ File img_file = get_child (font.get_backgrounds_folder (), "parts"); foreach (Attribute attr in tag.get_attributes ()) { if (attr.get_name () == "sha1") {- img_file = img_file.get_child (attr.get_content () + ".png");+ img_file = get_child (img_file, attr.get_content () + ".png"); if (!img_file.query_exists ()) { warning (@"Background file has not been created yet. $((!) img_file.get_path ())");@@ -68,7 +68,7 @@ public class BirdFontPart : GLib.Object{ font.background_images.clear (); bfp_dir = File.new_for_path (root_directory);- image_dir = bfp_dir.get_child ("images");+ image_dir = get_child (bfp_dir, "images"); copy_backgrounds ((!) image_dir.get_path ()); foreach (string fn in parts) {@@ -278,6 +278,7 @@ public class BirdFontPart : GLib.Object{ File image_dir; BackgroundImage bg; File found;+ File parts; File dest; image_dir = File.new_for_path (folder);@@ -295,13 +296,14 @@ public class BirdFontPart : GLib.Object{ name = info.get_name (); if (info.get_file_type () == FileType.DIRECTORY) {- found = image_dir.get_child (name);+ found = get_child (image_dir, name); copy_backgrounds ((!) found.get_path ()); } if (name.has_suffix (".png")) {- found = image_dir.get_child (name);- dest = font.get_backgrounds_folder ().get_child ("parts").get_child (name);+ found = get_child (image_dir, name);+ parts = get_child (font.get_backgrounds_folder (), "parts");+ dest = get_child (parts, name); bg = new BackgroundImage ((!) found.get_path ()); bg.create_background_folders (font); bg.copy_if_new (dest);@@ -377,11 +379,11 @@ public class BirdFontPart : GLib.Object{ if (directory.has_suffix (font.get_full_name ())) { bfp_dir = dir; } else {- bfp_dir = dir.get_child (font.get_full_name ());+ bfp_dir = get_child (dir, font.get_full_name ()); } while (bfp_dir.query_exists ()) {- bfp_dir = dir.get_child (@"$(font.get_full_name ())_$(i)");+ bfp_dir = get_child (dir, @"$(font.get_full_name ())_$(i)"); i++; } @@ -429,9 +431,9 @@ public class BirdFontPart : GLib.Object{ info = (!) fi; name = info.get_name (); if (info.get_file_type () == FileType.DIRECTORY) {- find_parts ((!) ((!) start.get_child (name)).get_path ());+ find_parts ((!) ((!) get_child (start, name)).get_path ()); } else if (name.has_suffix (".bfp")) {- found = start.get_child (name);+ found = get_child (start, name); parts.add ((!) found.get_path ()); } }@@ -470,7 +472,7 @@ public class BirdFontPart : GLib.Object{ File dir; dir = d;- dir = dir.get_child (subdir);+ dir = get_child (dir, subdir); if (!dir.query_exists ()) { DirUtils.create ((!) dir.get_path (), 0755);@@ -497,7 +499,7 @@ public class BirdFontPart : GLib.Object{ dir = new_subdirectory (dir, subdir2); } - file = dir.get_child (name);+ file = get_child (dir, name); if (file.query_file_type (0) == FileType.DIRECTORY) { throw new FileError.FAILED (@"Can't save font, $name is a directory.");@@ -217,7 +217,7 @@ class CutBackgroundTool : Tool { string fn; double wc, hc; - img_dir = f.get_backgrounds_folder ().get_child ("parts");+ img_dir = get_child (f.get_backgrounds_folder (), "parts"); if (!img_dir.query_exists ()) { if (DirUtils.create_with_parents ((!) img_dir.get_path (), 755) != 0) {@@ -422,7 +422,7 @@ os.put_string ( SvgFontFormatWriter fo; try {- file = folder.get_child (file_name);+ file = get_child (folder, file_name); if (file.query_exists ()) { file.delete ();@@ -132,7 +132,7 @@ public class FileDialogTab : FontDisplay { if (selected_filename == "") { action.cancel (); } else {- f = current_dir.get_child (selected_filename);+ f = get_child (current_dir, selected_filename); action.file_selected ((!)f.get_path ()); } });@@ -221,6 +221,7 @@ public class FileDialogTab : FontDisplay { double y = 0; string selected; bool dir = false;+ File f; selected = ""; @@ -252,7 +253,8 @@ public class FileDialogTab : FontDisplay { if (selected == "..") { propagate_files ((!)((!)current_dir.get_parent ()).get_path ()); } else {- propagate_files ((!)current_dir.get_child (selected).get_path ());+ f = get_child (current_dir, selected);+ propagate_files ((!) f.get_path ()); } } }@@ -107,7 +107,7 @@ public class FileTab : FontDisplay { } backup_file = BirdFont.get_backup_directory ();- backup_file = backup_file.get_child (file_name);+ backup_file = get_child (backup_file, file_name); load_font ((!) backup_file.get_path ()); } @@ -120,7 +120,7 @@ public class FileTab : FontDisplay { try { backup_file = BirdFont.get_backup_directory ();- backup_file = backup_file.get_child (file_name);+ backup_file = get_child (backup_file, file_name); if (backup_file.query_exists ()) { backup_file.delete (); }@@ -292,7 +292,7 @@ public class FileTab : FontDisplay { File thumbnail; double u = MainWindow.units; - thumbnail = BirdFont.get_thumbnail_directory ().get_child (backup);+ thumbnail = get_child (BirdFont.get_thumbnail_directory (), backup); draw_background (cr, allocation, y, color); @@ -446,7 +446,7 @@ public class FileTab : FontDisplay { enumerator = dir.enumerate_children (FileAttribute.STANDARD_NAME, 0); while ((file_info = enumerator.next_file ()) != null) { file_name = ((!) file_info).get_name ();- backup_file = dir.get_child (file_name);+ backup_file = get_child (dir, file_name); backup_file.delete (); } } catch (Error e) {@@ -153,7 +153,7 @@ public class Font : GLib.Object { public File get_backgrounds_folder () { string fn = @"$(get_name ()) backgrounds";- File f = BirdFont.get_settings_directory ().get_child (fn);+ File f = get_child (BirdFont.get_settings_directory (), fn); return f; } @@ -528,7 +528,7 @@ public class Font : GLib.Object { File file; string backup_file; - new_file = dir.get_child (@"$(name).bf");+ new_file = get_child (dir, @"$(name).bf"); backup_file = (!) ((!) new_file).get_path (); try {@@ -549,7 +549,7 @@ public class Font : GLib.Object { string backup_file; BirdFontFile birdfont_file = new BirdFontFile (this); - temp_file = dir.get_child (@"$(name).bf");+ temp_file = get_child (dir, @"$(name).bf"); backup_file = (!) ((!) temp_file).get_path (); backup_file = backup_file.replace (" ", "_"); @@ -104,7 +104,7 @@ public class Preferences { } printd ("get settings file");- settings = app_dir.get_child ("settings");+ settings = get_child (app_dir, "settings"); if (is_null (settings)) { warning ("No setting directory.");@@ -158,7 +158,7 @@ public class Preferences { public static void save () { try { File app_dir = BirdFont.get_settings_directory ();- File settings = app_dir.get_child ("settings");+ File settings = get_child (app_dir, "settings"); return_if_fail (app_dir.query_exists ()); @@ -38,7 +38,7 @@ public class Preview : FontDisplay { Font font = BirdFont.get_current_font (); string fn = get_html_file_name (); File dir = font.get_folder ();- File file = dir.get_child (fn);+ File file = get_child (dir, fn); if (!file.query_exists ()) { ExportTool.generate_html_document ((!)file.get_path (), font); @@ -51,7 +51,7 @@ public class Preview : FontDisplay { Font font = BirdFont.get_current_font (); string path = get_html_file_name (); File dir = font.get_folder ();- File file = dir.get_child (path);+ File file = get_child (dir, path); return file.query_exists (); } @@ -59,7 +59,7 @@ public class Preview : FontDisplay { Font font = BirdFont.get_current_font (); string path = get_html_file_name (); File dir = font.get_folder ();- File file = dir.get_child (path);+ File file = get_child (dir, path); ExportTool.generate_html_document ((!)file.get_path (), font); } @@ -67,7 +67,7 @@ public class Preview : FontDisplay { Font font = BirdFont.get_current_font (); string path = get_html_file_name (); File dir = font.get_folder ();- File file = dir.get_child (path);+ File file = get_child (dir, path); try { file.delete (); } catch (Error e) {@@ -92,7 +92,7 @@ public class Preview : FontDisplay { Font font = BirdFont.get_current_font (); string html = get_html_file_name (); File dir = font.get_folder ();- File file = dir.get_child (html);+ File file = get_child (dir, html); return "file:///" + (!) file.get_path (); } @@ -115,9 +115,9 @@ public class Preview : FontDisplay { preview_directory = BirdFont.get_preview_directory (); - f_ttf = font.get_folder ().get_child (@"$(font.get_full_name ()).ttf");- f_eot = font.get_folder ().get_child (@"$(font.get_full_name ()).eot");- f_svg = font.get_folder ().get_child (@"$(font.get_full_name ()).svg");+ f_ttf = get_child (font.get_folder (), @"$(font.get_full_name ()).ttf");+ f_eot = get_child (font.get_folder (), @"$(font.get_full_name ()).eot");+ f_svg = get_child (font.get_folder (), @"$(font.get_full_name ()).svg"); if (!f_ttf.query_exists ()) { warning ("TTF file does not exist.");@@ -207,7 +207,7 @@ class TestCases { warning ("TTF export failed."); } - f = f.get_child (font.get_name () + ".ttf");+ f = get_child (f, font.get_name () + ".ttf"); if (!f.query_exists ()) { warning ("File does not exist."); }@@ -345,7 +345,7 @@ class TestCases { DataOutputStream d; FileOutputStream? os; - temp_file = BirdFont.get_settings_directory ().get_child ("illustrator_test.svg");+ temp_file = get_child (BirdFont.get_settings_directory (), "illustrator_test.svg"); if (temp_file.query_exists ()) { temp_file.delete ();@@ -439,7 +439,7 @@ class TestCases { DataOutputStream d; FileOutputStream? os; - temp_file = BirdFont.get_settings_directory ().get_child ("inkscape_test.svg");+ temp_file = get_child (BirdFont.get_settings_directory (), "inkscape_test.svg"); if (temp_file.query_exists ()) { temp_file.delete ();