+std::wstring clean_path(std::wstring path)
+{
+ boost::replace_all(path, L"\\\\", L"/");
+ boost::replace_all(path, L"\\", L"/");
+
+ return path;
+}
+
+std::wstring ensure_trailing_slash(std::wstring folder)
+{
+ if (folder.at(folder.length() - 1) != L'/')
+ folder.append(L"/");
+
+ return folder;
+}
+
+std::wstring resolve_or_create(const std::wstring& folder)
+{
+ auto found_path = find_case_insensitive(folder);
+
+ if (found_path)
+ return *found_path;
+ else
+ {
+ boost::system::error_code ec;
+ boost::filesystem::create_directories(folder, ec);
+
+ if (ec)
+ CASPAR_THROW_EXCEPTION(user_error() << msg_info("Failed to create directory " + u8(folder) + " (" + ec.message() + ")"));
+
+ return folder;
+ }
+}
+
+void ensure_writable(const std::wstring& folder)
+{
+ static const std::wstring CREATE_FILE_TEST = L"casparcg_test_writable.empty";
+
+ boost::system::error_code ec;
+ boost::filesystem::path test_file(folder + L"/" + CREATE_FILE_TEST);
+ boost::filesystem::ofstream out(folder + L"/" + CREATE_FILE_TEST);
+
+ if (out.fail())
+ {
+ boost::filesystem::remove(test_file, ec);
+ CASPAR_THROW_EXCEPTION(user_error() << msg_info(L"Directory " + folder + L" is not writable."));
+ }
+
+ out.close();
+ boost::filesystem::remove(test_file, ec);
+}
+