- ustring::size_type pos;
- bool ret = false;
-
- isnew = false;
-
- if (pathstr[0] != '/') {
-
- /* non-absolute pathname: find pathstr in search path */
-
- vector<ustring> dirs;
- int cnt;
- ustring fullpath;
- ustring keeppath;
-
- if (search_path.length() == 0) {
- error << _("FileSource: search path not set") << endmsg;
- goto out;
- }
-
- split (search_path, dirs, ':');
-
- cnt = 0;
-
- for (vector<ustring>::iterator i = dirs.begin(); i != dirs.end(); ++i) {
-
- fullpath = *i;
- if (fullpath[fullpath.length()-1] != '/') {
- fullpath += '/';
- }
-
- fullpath += pathstr;
-
- /* i (paul) made a nasty design error by using ':' as a special character in
- Ardour 0.99 .. this hack tries to make things sort of work.
- */
-
- if ((pos = pathstr.find_last_of (':')) != ustring::npos) {
-
- if (Glib::file_test (fullpath, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
-
- /* its a real file, no problem */
-
- keeppath = fullpath;
- ++cnt;
-
- } else {
-
- if (must_exist) {
-
- /* might be an older session using file:channel syntax. see if the version
- without the :suffix exists
- */
-
- ustring shorter = pathstr.substr (0, pos);
- fullpath = *i;
-
- if (fullpath[fullpath.length()-1] != '/') {
- fullpath += '/';
- }
-
- fullpath += shorter;
-
- if (Glib::file_test (pathstr, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
- chan = atoi (pathstr.substr (pos+1));
- pathstr = shorter;
- keeppath = fullpath;
- ++cnt;
- }
-
- } else {
-
- /* new derived file (e.g. for timefx) being created in a newer session */
-
- }
- }
-
- } else {
-
- if (Glib::file_test (fullpath, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
- keeppath = fullpath;
- ++cnt;
- }
- }
- }
-
- if (cnt > 1) {
-
- error << string_compose (_("FileSource: \"%1\" is ambigous when searching %2\n\t"), pathstr, search_path) << endmsg;
- goto out;
-
- } else if (cnt == 0) {
-
- if (must_exist) {
- error << string_compose(_("Filesource: cannot find required file (%1): while searching %2"), pathstr, search_path) << endmsg;
- goto out;
- } else {
- isnew = true;
- }
- }
-
- _name = pathstr;
- _path = keeppath;
- ret = true;
-
- } else {
-
- /* external files and/or very very old style sessions include full paths */
-
- /* ugh, handle ':' situation */
-
- if ((pos = pathstr.find_last_of (':')) != ustring::npos) {
-
- ustring shorter = pathstr.substr (0, pos);
-
- if (Glib::file_test (shorter, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
- chan = atoi (pathstr.substr (pos+1));
- pathstr = shorter;
- }
- }
-
- _path = pathstr;
-
- if (is_embedded()) {
- _name = pathstr;
- } else {
- _name = pathstr.substr (pathstr.find_last_of ('/') + 1);
- }
-
- if (!Glib::file_test (pathstr, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
-
- /* file does not exist or we cannot read it */
-
- if (must_exist) {
- error << string_compose(_("Filesource: cannot find required file (%1): %2"), _path, strerror (errno)) << endmsg;
- goto out;
- }
-
- if (errno != ENOENT) {
- error << string_compose(_("Filesource: cannot check for existing file (%1): %2"), _path, strerror (errno)) << endmsg;
- goto out;
- }
-
- /* a new file */
-
- isnew = true;
- ret = true;
-
- } else {
-
- /* already exists */
-
- ret = true;
-
- }
- }
-
- out:
- return ret;
-}
-
-void
-AudioFileSource::set_search_path (ustring p)
-{
- search_path = p;