The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Fix the drive letter bug on Windows

These changes was commited to the Birdfont repository Wed, 15 Oct 2014 12:08:42 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Wed, 15 Oct 2014 12:08:42 +0000 (14:08 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Wed, 15 Oct 2014 12:11:51 +0000 (14:11 +0200)
commit d5afd980f80179b4cd1c41bc9f743724e2f10a42
tree 5b2e515f5a58ce0985f88127b28ae962b98dcbfc
parent 9df4a319cb91f9c108f64db07f1b51e85576fa9f
Fix the drive letter bug on Windows

13 files changed:
libbirdfont/BackgroundImage.vala
libbirdfont/BirdFont.vala
libbirdfont/BirdFontFile.vala
libbirdfont/BirdFontPart.vala
libbirdfont/CutBackgroundTool.vala
libbirdfont/ExportTool.vala
libbirdfont/FileDialogTab.vala
libbirdfont/FileTab.vala
libbirdfont/Font.vala
libbirdfont/Preferences.vala
libbirdfont/Preview.vala
libbirdfont/TestCases.vala
--- a/libbirdfont/BackgroundImage.vala +++ b/libbirdfont/BackgroundImage.vala @@ -233,7 +233,7 @@ 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 @@ 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 ()) {
--- a/libbirdfont/BirdFont.vala +++ b/libbirdfont/BirdFont.vala @@ -533,7 +533,7 @@ 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 @@ } 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 @@ 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 @@ 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 @@ 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,4 +685,29 @@ } } + /** 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); + } + + }
--- a/libbirdfont/BirdFontFile.vala +++ b/libbirdfont/BirdFontFile.vala @@ -796,13 +796,13 @@ 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 @@ 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 ())");
--- a/libbirdfont/BirdFontPart.vala +++ b/libbirdfont/BirdFontPart.vala @@ -68,7 +68,7 @@ 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 @@ File image_dir; BackgroundImage bg; File found; + File parts; File dest; image_dir = File.new_for_path (folder); @@ -295,13 +296,14 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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.");
--- a/libbirdfont/CutBackgroundTool.vala +++ b/libbirdfont/CutBackgroundTool.vala @@ -217,7 +217,7 @@ 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) {
--- a/libbirdfont/ExportTool.vala +++ b/libbirdfont/ExportTool.vala @@ -422,7 +422,7 @@ SvgFontFormatWriter fo; try { - file = folder.get_child (file_name); + file = get_child (folder, file_name); if (file.query_exists ()) { file.delete ();
--- a/libbirdfont/FileDialogTab.vala +++ b/libbirdfont/FileDialogTab.vala @@ -132,7 +132,7 @@ 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 @@ double y = 0; string selected; bool dir = false; + File f; selected = ""; @@ -252,7 +253,8 @@ 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 ()); } } }
--- a/libbirdfont/FileTab.vala +++ b/libbirdfont/FileTab.vala @@ -107,7 +107,7 @@ } 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 @@ 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 @@ 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 @@ 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) {
--- a/libbirdfont/Font.vala +++ b/libbirdfont/Font.vala @@ -153,7 +153,7 @@ 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 @@ 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 @@ 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 (" ", "_");
--- a/libbirdfont/Preferences.vala +++ b/libbirdfont/Preferences.vala @@ -104,7 +104,7 @@ } 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 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 ());
--- a/libbirdfont/Preview.vala +++ b/libbirdfont/Preview.vala @@ -38,7 +38,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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.");
--- a/libbirdfont/TestCases.vala +++ b/libbirdfont/TestCases.vala @@ -207,7 +207,7 @@ 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 @@ 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 @@ 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 ();