[ease/themes] [editor] Create media directory if it doesn't exist
- From: Nate Stedman <natesm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ease/themes] [editor] Create media directory if it doesn't exist
- Date: Fri, 23 Jul 2010 17:57:50 +0000 (UTC)
commit 5ed4cdd6e6892d93300e63382afca5735ab22b5d
Author: Nate Stedman <natesm gmail com>
Date: Fri Jul 23 13:57:42 2010 -0400
[editor] Create media directory if it doesn't exist
- Media directory is created when adding new media
if necessary.
- If a media file's filename is already taken, the
file is assigned a new name when copied.
src/ease-slide-set.vala | 23 ++++++++++++++++++-----
1 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/src/ease-slide-set.vala b/src/ease-slide-set.vala
index cff61ff..df2aa5a 100644
--- a/src/ease-slide-set.vala
+++ b/src/ease-slide-set.vala
@@ -123,13 +123,26 @@ public abstract class Ease.SlideSet : Object
*/
public string add_media_file(string file) throws GLib.Error
{
+ // create the media directory if necessary
+ var media = File.new_for_path(Path.build_filename(path, MEDIA_PATH));
+ if (!media.query_exists(null)) media.make_directory_with_parents(null);
+
+ // create file paths
var orig = File.new_for_path(file);
- var dest = File.new_for_path(Path.build_filename(path,
- MEDIA_PATH,
- orig.get_basename()));
- orig.copy(dest, 0, null, null);
+ var rel_path = Path.build_filename(MEDIA_PATH, orig.get_basename());
+ var dest = File.new_for_path(Path.build_filename(path, rel_path));
+
+ // if the file exists, we need a new filename
+ for (int i = 0; dest.query_exists(null); i++)
+ {
+ rel_path = Path.build_filename(MEDIA_PATH, i.to_string() + "-" +
+ orig.get_basename());
+ dest = File.new_for_path(Path.build_filename(path, rel_path));
+ }
- return Path.build_filename(MEDIA_PATH, orig.get_basename());
+ // copy the file and return its path
+ orig.copy(dest, 0, null, null);
+ return rel_path;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]