3 * Copyright (C) 2008-2009 Florian Brosch
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Brosch Florian <flo.brosch@gmail.com>
25 [CCode (cprefix
= "", cname
= "PACKAGE_ICONDIR")]
26 public extern const string icons_dir
;
29 * Makes a copy of the file src to dest.
31 * @param src the file to copy
32 * @param dest the destination path
34 public bool copy_file (string src
, string dest
) {
35 GLib
.FileStream fsrc
= GLib
.FileStream
.open (src
, "rb");
40 GLib
.FileStream fdest
= GLib
.FileStream
.open (dest
, "wb");
45 for (int c
= fsrc
.getc() ; !fsrc
.eof() ; c
= fsrc
.getc()) {
53 * Makes a copy of the directory src to dest.
55 * @param src the directory to copy
56 * @param dest the destination path
58 public bool copy_directory (string src
, string dest
) {
60 GLib
.Dir dir
= GLib
.Dir
.open (src
);
61 for (string? file
= dir
.read_name (); file
!= null; file
= dir
.read_name ()) {
62 string src_file_path
= GLib
.Path
.build_filename (src
, file
);
63 string dest_file_path
= GLib
.Path
.build_filename (dest
, file
);
64 if (GLib
.FileUtils
.test (src_file_path
, GLib
.FileTest
.IS_DIR
)) {
65 GLib
.DirUtils
.create (dest_file_path
, 0755); // mkdir if necessary
66 if (!copy_directory (src_file_path
, dest_file_path
)) { // copy directories recursively
70 if (!copy_file (src_file_path
, dest_file_path
)) {
76 catch (GLib
.FileError err
) {
83 * A recursive directory delete function
85 * @param rpath the directory to remove
87 public bool remove_directory (string rpath
) {
89 GLib
.Dir dir
= GLib
.Dir
.open ( rpath
);
93 for (weak string entry
= dir
.read_name(); entry
!= null ; entry
= dir
.read_name()) {
94 string path
= rpath
+ entry
;
96 bool is_dir
= GLib
.FileUtils
.test (path
, GLib
.FileTest
.IS_DIR
);
98 bool tmp
= remove_directory (path
);
103 int tmp
= GLib
.FileUtils
.unlink (path
);
109 } catch (GLib
.FileError err
) {