#include <utility>
#include <fstream>
-#ifdef HAVE_SSTREAM
-#include <sstream>
-#else
-#include <strstream>
-#endif
+#include "Lsstream.h"
#ifdef __GNUG__
#pragma implementation "filetools.h"
return -1;
}
struct dirent * de;
+ int return_value = 0;
while ((de = readdir(dir))) {
string temp = de->d_name;
if (temp == "." || temp == "..")
lyxerr.debug() << "Deleting file: " << unlinkpath << endl;
- if (remove(unlinkpath.c_str()))
+ bool deleted = true;
+ if (FileInfo(unlinkpath).isDir())
+ deleted = (DeleteAllFilesInDir(unlinkpath) == 0);
+ deleted &= (remove(unlinkpath.c_str()) == 0);
+ if (!deleted) {
WriteFSAlert (_("Error! Could not remove file:"),
unlinkpath);
+ return_value = -1;
+ }
}
closedir(dir);
- return 0;
+ return return_value;
}
FileInfo finfo(fname);
if (finfo.exist()) {
ifstream ifs(fname.c_str());
-#ifdef HAVE_SSTREAM
std::ostringstream ofs;
-#else
-#warning The rumour goes that this might leak, but who really cares?
- ostrstream ofs;
-#endif
if (ifs && ofs) {
ofs << ifs.rdbuf();
ifs.close();
-#ifdef HAVE_SSTREAM
return ofs.str().c_str();
-#else
- ofs << '\0';
- char const * tmp = ofs.str();
- string ret(tmp);
- delete[] tmp;
- return ret;
-#endif
}
}
lyxerr << "LyX was not able to read file '" << fname << "'" << endl;
}
+/// Return the extension of the file (not including the .)
+string const GetExtension(string const & name)
+{
+ string::size_type last_slash = name.rfind('/');
+ string::size_type last_dot = name.rfind('.');
+ if (last_dot != string::npos &&
+ (last_slash == string::npos || last_dot > last_slash))
+ return name.substr(last_dot + 1,
+ name.length() - (last_dot + 1));
+ else
+ return string();
+}
+
+
// Creates a nice compact path for displaying
string const
MakeDisplayPath (string const & path, unsigned int threshold)
return c.first != -1 ? strip(c.second, '\n') : string();
}
+
void removeAutosaveFile(string const & filename)
{
string a = OnlyPath(filename);