FRESH AND RAW
[potpourri.git] / src / core / MediaLoader.cpp
blobdb6c406aceca5000606bcc0a92702942b6760715
1 // Copyright 2008 Brian Caine
3 // This file is part of Potpourri.
5 // Potpourri is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Potpourri is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTIBILITY of FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Potpourri. If not, see <http://www.gnu.org/licenses/>.
19 // NOTES:
21 // The source for the medialoader class.
23 #include <iostream>
24 #include <string>
25 #include <stdexcept>
27 #include "../../include/core/MediaLoader.h"
29 #include "../../include/core/common.h"
30 #include "../../include/core/cURLDirectory.h"
31 #include "../../include/core/LocalDirectory.h"
33 using namespace fragrant;
35 MediaLoader::MediaLoader()
39 MediaLoader::~MediaLoader()
42 std::string MediaLoader::loadMedia(std::string source)
44 bool relative;
45 bool local;
47 std::string base;
49 try
51 ParsedPath path = parsePath(source);
52 base = path.protocol + protocol_host_separator +
53 path.host + path_separator;
56 catch (std::runtime_error& e)
58 local = true;
60 relative = splitPath(source).size() &&
61 splitPath(source).at(0) != (std::string("") + path_separator);
63 if (!relative)
64 base = path_separator;
65 else
66 base = current_dir;
69 std::string results;
71 if (local)
73 LocalDirectory dir = LocalDirectory(base, plugin_map);
74 results = dir.getFile(source);
77 else
79 cURLDirectory dir = cURLDirectory(base, plugin_map);
80 results = dir.getFile(source);
83 return results;
86 std::map<std::string, archive_function>& MediaLoader::plugins()
88 return plugin_map;
91 Game* MediaLoader::getGame()
93 return game;
96 void MediaLoader::setGame(Game* ngame)
98 game = ngame;
99 return;