| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | // SPDX-License-Identifier: GPL-2.0
 | 
					
						
							|  |  |  | /* implements iOS specific functions */ | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <dirent.h>
 | 
					
						
							|  |  |  | #include <fnmatch.h>
 | 
					
						
							| 
									
										
										
										
											2019-08-05 20:07:10 +02:00
										 |  |  | #include "file.h"
 | 
					
						
							| 
									
										
										
										
											2022-03-12 10:44:37 +01:00
										 |  |  | #include "device.h"
 | 
					
						
							| 
									
										
										
										
											2024-06-30 21:17:17 +02:00
										 |  |  | #include "qthelper.h"
 | 
					
						
							|  |  |  | #include "subsurfacestartup.h"
 | 
					
						
							| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | #include <CoreFoundation/CoreFoundation.h>
 | 
					
						
							|  |  |  | #if !defined(__IPHONE_5_0)
 | 
					
						
							|  |  |  | #include <CoreServices/CoreServices.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #include <mach-o/dyld.h>
 | 
					
						
							|  |  |  | #include <sys/syslimits.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <fcntl.h>
 | 
					
						
							|  |  |  | #include <unistd.h>
 | 
					
						
							| 
									
										
										
										
											2019-08-05 20:07:10 +02:00
										 |  |  | #include <zip.h>
 | 
					
						
							| 
									
										
										
										
											2023-04-29 11:43:17 +02:00
										 |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <QStandardPaths>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 11:43:17 +02:00
										 |  |  | static std::string system_default_path() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Qt appears to find a working path for us - let's just go with that
 | 
					
						
							|  |  |  | 	return QStandardPaths::standardLocations(QStandardPaths::DataLocation).first().toStdString(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static std::string make_default_filename() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return system_default_path() + "/subsurface.xml"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-13 22:59:32 +02:00
										 |  |  | using namespace std::string_literals; | 
					
						
							|  |  |  | std::string system_divelist_default_font = "Arial"s; | 
					
						
							| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | double system_divelist_default_font_size = -1.0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:53:41 +02:00
										 |  |  | void subsurface_OS_pref_setup() | 
					
						
							| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	// nothing
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-13 22:59:32 +02:00
										 |  |  | bool subsurface_ignore_font(const std::string &) | 
					
						
							| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	// there are no old default fonts that we would want to ignore
 | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-13 22:59:32 +02:00
										 |  |  | std::string system_default_directory() | 
					
						
							| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-04-29 11:43:17 +02:00
										 |  |  | 	static const std::string path = system_default_path(); | 
					
						
							| 
									
										
										
										
											2024-06-13 22:59:32 +02:00
										 |  |  | 	return path; | 
					
						
							| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-13 22:59:32 +02:00
										 |  |  | std::string system_default_filename() | 
					
						
							| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2023-04-29 11:43:17 +02:00
										 |  |  | 	static const std::string fn = make_default_filename(); | 
					
						
							| 
									
										
										
										
											2024-06-13 22:59:32 +02:00
										 |  |  | 	return fn; | 
					
						
							| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-27 10:32:14 -07:00
										 |  |  | int enumerate_devices(device_callback_t, void *, unsigned int) | 
					
						
							| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	// we can't read from devices on iOS
 | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* NOP wrappers to comform with windows.c */ | 
					
						
							|  |  |  | int subsurface_rename(const char *path, const char *newpath) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return rename(path, newpath); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int subsurface_open(const char *path, int oflags, mode_t mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return open(path, oflags, mode); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | FILE *subsurface_fopen(const char *path, const char *mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return fopen(path, mode); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void *subsurface_opendir(const char *path) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (void *)opendir(path); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int subsurface_access(const char *path, int mode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return access(path, mode); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int subsurface_stat(const char* path, struct stat* buf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return stat(path, buf); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return zip_open(path, flags, errorp); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int subsurface_zip_close(struct zip *zip) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return zip_close(zip); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* win32 console */ | 
					
						
							| 
									
										
										
										
											2024-05-04 18:53:41 +02:00
										 |  |  | void subsurface_console_init() | 
					
						
							| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* NOP */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-04 18:53:41 +02:00
										 |  |  | void subsurface_console_exit() | 
					
						
							| 
									
										
										
										
											2018-04-12 22:17:34 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* NOP */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool subsurface_user_is_root() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } |