]> git.jsancho.org Git - guile-irrlicht.git/blob - src/file-system.cpp
4c643ae3e05272eb5abc695ed254cff0fd21a822
[guile-irrlicht.git] / src / file-system.cpp
1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
2
3    Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
4
5    This file is part of guile-irrlicht.
6
7    guile-irrlicht is free software; you can redistribute it and/or modify
8    it under the terms of the GNU Lesser General Public License as
9    published by the Free Software Foundation; either version 3 of the
10    License, or (at your option) any later version.
11
12    guile-irrlicht is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15    General Public License for more details.
16
17    You should have received a copy of the GNU Lesser General Public
18    License along with guile-irrlicht. If not, see
19    <http://www.gnu.org/licenses/>.
20 */
21
22 #include <irrlicht/irrlicht.h>
23 #include <libguile.h>
24
25 #include "device.h"
26 #include "file-archive.h"
27 #include "file-system.h"
28 #include "gsubr.h"
29 #include "gui-environment.h"
30 #include "scene-manager.h"
31
32 extern "C" {
33
34   void
35   init_file_system (void)
36   {
37     init_file_system_type ();
38     DEFINE_GSUBR ("add-file-archive!", 2, 0, 1, irr_io_addFileArchive);
39     DEFINE_GSUBR ("get-file-system", 1, 0, 0, irr_getFileSystem);
40   }
41
42   DEFINE_WRAPPED_TYPE (irr::io::IFileSystem*, "file-system",
43                        init_file_system_type, file_system_p,
44                        wrap_file_system, unwrap_file_system);
45
46   SCM
47   irr_io_addFileArchive (SCM wrapped_file_system,
48                          SCM filename,
49                          SCM rest)
50   {
51     SCM ignore_case = SCM_BOOL_T;
52     SCM ignore_paths = SCM_BOOL_T;
53     SCM archive_type = scm_from_utf8_symbol ("unknown");
54     SCM password = scm_from_utf8_string ("");
55     SCM ret_archive = SCM_BOOL_F;
56
57     scm_c_bind_keyword_arguments ("add-file-archive!", rest, (scm_t_keyword_arguments_flags)0,
58                                   scm_from_utf8_keyword ("ignore-case"), &ignore_case,
59                                   scm_from_utf8_keyword ("ignore-paths"), &ignore_paths,
60                                   scm_from_utf8_keyword ("archive-type"), &archive_type,
61                                   scm_from_utf8_keyword ("password"), &password,
62                                   scm_from_utf8_keyword ("ret-archive"), &ret_archive,
63                                   SCM_UNDEFINED);
64
65     irr::io::IFileArchive** retArchiveReference = 0;
66     if (!scm_is_false (ret_archive))
67       {
68         irr::io::IFileArchive* retArchive = unwrap_file_archive (ret_archive);
69         retArchiveReference = &retArchive;
70       }
71     irr::io::IFileSystem* file_system = unwrap_file_system (wrapped_file_system);
72     return scm_from_bool
73       (file_system->addFileArchive (scm_to_utf8_stringn (filename, NULL),
74                                     scm_to_bool (ignore_case),
75                                     scm_to_bool (ignore_paths),
76                                     scm_to_file_archive_type (archive_type),
77                                     scm_to_utf8_stringn (password, NULL),
78                                     retArchiveReference));
79   }
80
81   SCM
82   irr_getFileSystem (SCM wrapped_obj)
83   {
84     irr::io::IFileSystem* file_system;
85     if (gui_environment_p (wrapped_obj))
86       {
87         file_system = unwrap_gui_environment (wrapped_obj)->getFileSystem ();
88       }
89     else if (device_p (wrapped_obj))
90       {
91         file_system = unwrap_device (wrapped_obj)->getFileSystem ();
92       }
93     else if (scene_manager_p (wrapped_obj))
94       {
95         file_system = unwrap_scene_manager (wrapped_obj)->getFileSystem ();
96       }
97     else
98       {
99         scm_error (scm_arg_type_key, NULL, "Cannot get file system from object: ~S",
100                    scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
101       }
102     return wrap_file_system (file_system);
103   }
104
105 }