Use PBD::sys::copy_file in ARDOUR::create_backup_file
[ardour.git] / libs / ardour / session_state_utils.cc
1 /*
2         Copyright (C) 2007 Tim Mayberry
3
4         This program is free software; you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation; either version 2 of the License, or
7         (at your option) any later version.
8
9         This program is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with this program; if not, write to the Free Software
16         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19 #include <algorithm>
20
21 #include <glibmm/fileutils.h>
22
23 #include <giomm/file.h>
24
25 #include "pbd/basename.h"
26 #include "pbd/compose.h"
27 #include "pbd/error.h"
28 #include "pbd/file_utils.h"
29 #include "pbd/filesystem.h"
30
31 #include "ardour/session_state_utils.h"
32 #include "ardour/filename_extensions.h"
33
34 #include "i18n.h"
35
36 using namespace std;
37 using namespace PBD;
38
39 namespace ARDOUR {
40
41 bool
42 create_backup_file (const std::string & file_path)
43 {
44         return sys::copy_file (file_path, file_path + backup_suffix);
45 }
46
47 void
48 get_state_files_in_directory (const std::string & directory_path,
49                               vector<std::string> & result)
50 {
51         Glib::PatternSpec state_file_pattern('*' + string(statefile_suffix));
52
53         find_matching_files_in_directory (directory_path, state_file_pattern,
54                         result);
55 }
56
57 vector<string>
58 get_file_names_no_extension (const vector<std::string> & file_paths)
59 {
60         vector<string> result;
61
62         std::transform (file_paths.begin(), file_paths.end(),
63                         std::back_inserter(result), PBD::basename_nosuffix);
64
65         sort (result.begin(), result.end(), std::less<string>());
66
67         return result;
68 }
69
70 } // namespace ARDOUR