@ -0,0 +1,3 @@ | |||
build | |||
dist | |||
.vscode |
@ -0,0 +1,339 @@ | |||
GNU GENERAL PUBLIC LICENSE | |||
Version 2, June 1991 | |||
Copyright (C) 1989, 1991 Free Software Foundation, Inc., | |||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |||
Everyone is permitted to copy and distribute verbatim copies | |||
of this license document, but changing it is not allowed. | |||
Preamble | |||
The licenses for most software are designed to take away your | |||
freedom to share and change it. By contrast, the GNU General Public | |||
License is intended to guarantee your freedom to share and change free | |||
software--to make sure the software is free for all its users. This | |||
General Public License applies to most of the Free Software | |||
Foundation's software and to any other program whose authors commit to | |||
using it. (Some other Free Software Foundation software is covered by | |||
the GNU Lesser General Public License instead.) You can apply it to | |||
your programs, too. | |||
When we speak of free software, we are referring to freedom, not | |||
price. Our General Public Licenses are designed to make sure that you | |||
have the freedom to distribute copies of free software (and charge for | |||
this service if you wish), that you receive source code or can get it | |||
if you want it, that you can change the software or use pieces of it | |||
in new free programs; and that you know you can do these things. | |||
To protect your rights, we need to make restrictions that forbid | |||
anyone to deny you these rights or to ask you to surrender the rights. | |||
These restrictions translate to certain responsibilities for you if you | |||
distribute copies of the software, or if you modify it. | |||
For example, if you distribute copies of such a program, whether | |||
gratis or for a fee, you must give the recipients all the rights that | |||
you have. You must make sure that they, too, receive or can get the | |||
source code. And you must show them these terms so they know their | |||
rights. | |||
We protect your rights with two steps: (1) copyright the software, and | |||
(2) offer you this license which gives you legal permission to copy, | |||
distribute and/or modify the software. | |||
Also, for each author's protection and ours, we want to make certain | |||
that everyone understands that there is no warranty for this free | |||
software. If the software is modified by someone else and passed on, we | |||
want its recipients to know that what they have is not the original, so | |||
that any problems introduced by others will not reflect on the original | |||
authors' reputations. | |||
Finally, any free program is threatened constantly by software | |||
patents. We wish to avoid the danger that redistributors of a free | |||
program will individually obtain patent licenses, in effect making the | |||
program proprietary. To prevent this, we have made it clear that any | |||
patent must be licensed for everyone's free use or not licensed at all. | |||
The precise terms and conditions for copying, distribution and | |||
modification follow. | |||
GNU GENERAL PUBLIC LICENSE | |||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | |||
0. This License applies to any program or other work which contains | |||
a notice placed by the copyright holder saying it may be distributed | |||
under the terms of this General Public License. The "Program", below, | |||
refers to any such program or work, and a "work based on the Program" | |||
means either the Program or any derivative work under copyright law: | |||
that is to say, a work containing the Program or a portion of it, | |||
either verbatim or with modifications and/or translated into another | |||
language. (Hereinafter, translation is included without limitation in | |||
the term "modification".) Each licensee is addressed as "you". | |||
Activities other than copying, distribution and modification are not | |||
covered by this License; they are outside its scope. The act of | |||
running the Program is not restricted, and the output from the Program | |||
is covered only if its contents constitute a work based on the | |||
Program (independent of having been made by running the Program). | |||
Whether that is true depends on what the Program does. | |||
1. You may copy and distribute verbatim copies of the Program's | |||
source code as you receive it, in any medium, provided that you | |||
conspicuously and appropriately publish on each copy an appropriate | |||
copyright notice and disclaimer of warranty; keep intact all the | |||
notices that refer to this License and to the absence of any warranty; | |||
and give any other recipients of the Program a copy of this License | |||
along with the Program. | |||
You may charge a fee for the physical act of transferring a copy, and | |||
you may at your option offer warranty protection in exchange for a fee. | |||
2. You may modify your copy or copies of the Program or any portion | |||
of it, thus forming a work based on the Program, and copy and | |||
distribute such modifications or work under the terms of Section 1 | |||
above, provided that you also meet all of these conditions: | |||
a) You must cause the modified files to carry prominent notices | |||
stating that you changed the files and the date of any change. | |||
b) You must cause any work that you distribute or publish, that in | |||
whole or in part contains or is derived from the Program or any | |||
part thereof, to be licensed as a whole at no charge to all third | |||
parties under the terms of this License. | |||
c) If the modified program normally reads commands interactively | |||
when run, you must cause it, when started running for such | |||
interactive use in the most ordinary way, to print or display an | |||
announcement including an appropriate copyright notice and a | |||
notice that there is no warranty (or else, saying that you provide | |||
a warranty) and that users may redistribute the program under | |||
these conditions, and telling the user how to view a copy of this | |||
License. (Exception: if the Program itself is interactive but | |||
does not normally print such an announcement, your work based on | |||
the Program is not required to print an announcement.) | |||
These requirements apply to the modified work as a whole. If | |||
identifiable sections of that work are not derived from the Program, | |||
and can be reasonably considered independent and separate works in | |||
themselves, then this License, and its terms, do not apply to those | |||
sections when you distribute them as separate works. But when you | |||
distribute the same sections as part of a whole which is a work based | |||
on the Program, the distribution of the whole must be on the terms of | |||
this License, whose permissions for other licensees extend to the | |||
entire whole, and thus to each and every part regardless of who wrote it. | |||
Thus, it is not the intent of this section to claim rights or contest | |||
your rights to work written entirely by you; rather, the intent is to | |||
exercise the right to control the distribution of derivative or | |||
collective works based on the Program. | |||
In addition, mere aggregation of another work not based on the Program | |||
with the Program (or with a work based on the Program) on a volume of | |||
a storage or distribution medium does not bring the other work under | |||
the scope of this License. | |||
3. You may copy and distribute the Program (or a work based on it, | |||
under Section 2) in object code or executable form under the terms of | |||
Sections 1 and 2 above provided that you also do one of the following: | |||
a) Accompany it with the complete corresponding machine-readable | |||
source code, which must be distributed under the terms of Sections | |||
1 and 2 above on a medium customarily used for software interchange; or, | |||
b) Accompany it with a written offer, valid for at least three | |||
years, to give any third party, for a charge no more than your | |||
cost of physically performing source distribution, a complete | |||
machine-readable copy of the corresponding source code, to be | |||
distributed under the terms of Sections 1 and 2 above on a medium | |||
customarily used for software interchange; or, | |||
c) Accompany it with the information you received as to the offer | |||
to distribute corresponding source code. (This alternative is | |||
allowed only for noncommercial distribution and only if you | |||
received the program in object code or executable form with such | |||
an offer, in accord with Subsection b above.) | |||
The source code for a work means the preferred form of the work for | |||
making modifications to it. For an executable work, complete source | |||
code means all the source code for all modules it contains, plus any | |||
associated interface definition files, plus the scripts used to | |||
control compilation and installation of the executable. However, as a | |||
special exception, the source code distributed need not include | |||
anything that is normally distributed (in either source or binary | |||
form) with the major components (compiler, kernel, and so on) of the | |||
operating system on which the executable runs, unless that component | |||
itself accompanies the executable. | |||
If distribution of executable or object code is made by offering | |||
access to copy from a designated place, then offering equivalent | |||
access to copy the source code from the same place counts as | |||
distribution of the source code, even though third parties are not | |||
compelled to copy the source along with the object code. | |||
4. You may not copy, modify, sublicense, or distribute the Program | |||
except as expressly provided under this License. Any attempt | |||
otherwise to copy, modify, sublicense or distribute the Program is | |||
void, and will automatically terminate your rights under this License. | |||
However, parties who have received copies, or rights, from you under | |||
this License will not have their licenses terminated so long as such | |||
parties remain in full compliance. | |||
5. You are not required to accept this License, since you have not | |||
signed it. However, nothing else grants you permission to modify or | |||
distribute the Program or its derivative works. These actions are | |||
prohibited by law if you do not accept this License. Therefore, by | |||
modifying or distributing the Program (or any work based on the | |||
Program), you indicate your acceptance of this License to do so, and | |||
all its terms and conditions for copying, distributing or modifying | |||
the Program or works based on it. | |||
6. Each time you redistribute the Program (or any work based on the | |||
Program), the recipient automatically receives a license from the | |||
original licensor to copy, distribute or modify the Program subject to | |||
these terms and conditions. You may not impose any further | |||
restrictions on the recipients' exercise of the rights granted herein. | |||
You are not responsible for enforcing compliance by third parties to | |||
this License. | |||
7. If, as a consequence of a court judgment or allegation of patent | |||
infringement or for any other reason (not limited to patent issues), | |||
conditions are imposed on you (whether by court order, agreement or | |||
otherwise) that contradict the conditions of this License, they do not | |||
excuse you from the conditions of this License. If you cannot | |||
distribute so as to satisfy simultaneously your obligations under this | |||
License and any other pertinent obligations, then as a consequence you | |||
may not distribute the Program at all. For example, if a patent | |||
license would not permit royalty-free redistribution of the Program by | |||
all those who receive copies directly or indirectly through you, then | |||
the only way you could satisfy both it and this License would be to | |||
refrain entirely from distribution of the Program. | |||
If any portion of this section is held invalid or unenforceable under | |||
any particular circumstance, the balance of the section is intended to | |||
apply and the section as a whole is intended to apply in other | |||
circumstances. | |||
It is not the purpose of this section to induce you to infringe any | |||
patents or other property right claims or to contest validity of any | |||
such claims; this section has the sole purpose of protecting the | |||
integrity of the free software distribution system, which is | |||
implemented by public license practices. Many people have made | |||
generous contributions to the wide range of software distributed | |||
through that system in reliance on consistent application of that | |||
system; it is up to the author/donor to decide if he or she is willing | |||
to distribute software through any other system and a licensee cannot | |||
impose that choice. | |||
This section is intended to make thoroughly clear what is believed to | |||
be a consequence of the rest of this License. | |||
8. If the distribution and/or use of the Program is restricted in | |||
certain countries either by patents or by copyrighted interfaces, the | |||
original copyright holder who places the Program under this License | |||
may add an explicit geographical distribution limitation excluding | |||
those countries, so that distribution is permitted only in or among | |||
countries not thus excluded. In such case, this License incorporates | |||
the limitation as if written in the body of this License. | |||
9. The Free Software Foundation may publish revised and/or new versions | |||
of the General Public License from time to time. Such new versions will | |||
be similar in spirit to the present version, but may differ in detail to | |||
address new problems or concerns. | |||
Each version is given a distinguishing version number. If the Program | |||
specifies a version number of this License which applies to it and "any | |||
later version", you have the option of following the terms and conditions | |||
either of that version or of any later version published by the Free | |||
Software Foundation. If the Program does not specify a version number of | |||
this License, you may choose any version ever published by the Free Software | |||
Foundation. | |||
10. If you wish to incorporate parts of the Program into other free | |||
programs whose distribution conditions are different, write to the author | |||
to ask for permission. For software which is copyrighted by the Free | |||
Software Foundation, write to the Free Software Foundation; we sometimes | |||
make exceptions for this. Our decision will be guided by the two goals | |||
of preserving the free status of all derivatives of our free software and | |||
of promoting the sharing and reuse of software generally. | |||
NO WARRANTY | |||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | |||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN | |||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | |||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | |||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS | |||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE | |||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | |||
REPAIR OR CORRECTION. | |||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | |||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | |||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, | |||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING | |||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | |||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | |||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | |||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | |||
POSSIBILITY OF SUCH DAMAGES. | |||
END OF TERMS AND CONDITIONS | |||
How to Apply These Terms to Your New Programs | |||
If you develop a new program, and you want it to be of the greatest | |||
possible use to the public, the best way to achieve this is to make it | |||
free software which everyone can redistribute and change under these terms. | |||
To do so, attach the following notices to the program. It is safest | |||
to attach them to the start of each source file to most effectively | |||
convey the exclusion of warranty; and each file should have at least | |||
the "copyright" line and a pointer to where the full notice is found. | |||
<one line to give the program's name and a brief idea of what it does.> | |||
Copyright (C) <year> <name of author> | |||
This program is free software; you can redistribute it and/or modify | |||
it under the terms of the GNU General Public License as published by | |||
the Free Software Foundation; either version 2 of the License, or | |||
(at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | |||
You should have received a copy of the GNU General Public License along | |||
with this program; if not, write to the Free Software Foundation, Inc., | |||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |||
Also add information on how to contact you by electronic and paper mail. | |||
If the program is interactive, make it output a short notice like this | |||
when it starts in an interactive mode: | |||
Gnomovision version 69, Copyright (C) year name of author | |||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. | |||
This is free software, and you are welcome to redistribute it | |||
under certain conditions; type `show c' for details. | |||
The hypothetical commands `show w' and `show c' should show the appropriate | |||
parts of the General Public License. Of course, the commands you use may | |||
be called something other than `show w' and `show c'; they could even be | |||
mouse-clicks or menu items--whatever suits your program. | |||
You should also get your employer (if you work as a programmer) or your | |||
school, if any, to sign a "copyright disclaimer" for the program, if | |||
necessary. Here is a sample; alter the names: | |||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program | |||
`Gnomovision' (which makes passes at compilers) written by James Hacker. | |||
<signature of Ty Coon>, 1 April 1989 | |||
Ty Coon, President of Vice | |||
This General Public License does not permit incorporating your program into | |||
proprietary programs. If your program is a subroutine library, you may | |||
consider it more useful to permit linking proprietary applications with the | |||
library. If this is what you want to do, use the GNU Lesser General | |||
Public License instead of this License. |
@ -0,0 +1,199 @@ | |||
#--------------------------------------------------------------------------------- | |||
.SUFFIXES: | |||
#--------------------------------------------------------------------------------- | |||
ifeq ($(strip $(DEVKITPRO)),) | |||
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro") | |||
endif | |||
TOPDIR ?= $(CURDIR) | |||
include $(DEVKITPRO)/libnx/switch_rules | |||
#--------------------------------------------------------------------------------- | |||
# TARGET is the name of the output | |||
# BUILD is the directory where object files & intermediate files will be placed | |||
# SOURCES is a list of directories containing source code | |||
# DATA is a list of directories containing data files | |||
# INCLUDES is a list of directories containing header files | |||
# EXEFS_SRC is the optional input directory containing data copied into exefs, if anything this normally should only contain "main.npdm". | |||
# | |||
# NO_ICON: if set to anything, do not use icon. | |||
# NO_NACP: if set to anything, no .nacp file is generated. | |||
# APP_TITLE is the name of the app stored in the .nacp file (Optional) | |||
# APP_AUTHOR is the author of the app stored in the .nacp file (Optional) | |||
# APP_VERSION is the version of the app stored in the .nacp file (Optional) | |||
# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional) | |||
# ICON is the filename of the icon (.jpg), relative to the project folder. | |||
# If not set, it attempts to use one of the following (in this order): | |||
# - <Project name>.jpg | |||
# - icon.jpg | |||
# - <libnx folder>/default_icon.jpg | |||
#--------------------------------------------------------------------------------- | |||
TARGET := $(notdir $(CURDIR)) | |||
BUILD := build | |||
DIST := dist | |||
SOURCES := src src/minizip | |||
DATA := data | |||
INCLUDES := include | |||
EXEFS_SRC := exefs_src | |||
APP_TITLE := SD File Updater | |||
APP_AUTHOR := Steven Mattera | |||
APP_VERSION := 1.0.0 | |||
#--------------------------------------------------------------------------------- | |||
# options for code generation | |||
#--------------------------------------------------------------------------------- | |||
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE | |||
CFLAGS := -g -Wall -O2 -ffunction-sections \ | |||
$(ARCH) $(DEFINES) | |||
CFLAGS += $(INCLUDE) -D__SWITCH__ -DUSE_FILE32API | |||
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 | |||
ASFLAGS := -g $(ARCH) | |||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) | |||
LIBS := -lconfig -lcurl -lz -lnx | |||
#--------------------------------------------------------------------------------- | |||
# list of directories containing libraries, this must be the top level containing | |||
# include and lib | |||
#--------------------------------------------------------------------------------- | |||
LIBDIRS := $(PORTLIBS) $(LIBNX) | |||
#--------------------------------------------------------------------------------- | |||
# no real need to edit anything past this point unless you need to add additional | |||
# rules for different file extensions | |||
#--------------------------------------------------------------------------------- | |||
ifneq ($(BUILD),$(notdir $(CURDIR))) | |||
#--------------------------------------------------------------------------------- | |||
export OUTPUT := $(CURDIR)/$(DIST)/$(TARGET) | |||
export TOPDIR := $(CURDIR) | |||
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ | |||
$(foreach dir,$(DATA),$(CURDIR)/$(dir)) | |||
export DEPSDIR := $(CURDIR)/$(BUILD) | |||
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) | |||
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) | |||
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) | |||
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) | |||
#--------------------------------------------------------------------------------- | |||
# use CXX for linking C++ projects, CC for standard C | |||
#--------------------------------------------------------------------------------- | |||
ifeq ($(strip $(CPPFILES)),) | |||
#--------------------------------------------------------------------------------- | |||
export LD := $(CC) | |||
#--------------------------------------------------------------------------------- | |||
else | |||
#--------------------------------------------------------------------------------- | |||
export LD := $(CXX) | |||
#--------------------------------------------------------------------------------- | |||
endif | |||
#--------------------------------------------------------------------------------- | |||
export OFILES_BIN := $(addsuffix .o,$(BINFILES)) | |||
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) | |||
export OFILES := $(OFILES_BIN) $(OFILES_SRC) | |||
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) | |||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ | |||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \ | |||
-I$(CURDIR)/$(BUILD) | |||
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) | |||
export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC) | |||
ifeq ($(strip $(ICON)),) | |||
icons := $(wildcard *.jpg) | |||
ifneq (,$(findstring $(TARGET).jpg,$(icons))) | |||
export APP_ICON := $(TOPDIR)/$(TARGET).jpg | |||
else | |||
ifneq (,$(findstring icon.jpg,$(icons))) | |||
export APP_ICON := $(TOPDIR)/icon.jpg | |||
endif | |||
endif | |||
else | |||
export APP_ICON := $(TOPDIR)/$(ICON) | |||
endif | |||
ifeq ($(strip $(NO_ICON)),) | |||
export NROFLAGS += --icon=$(APP_ICON) | |||
endif | |||
ifeq ($(strip $(NO_NACP)),) | |||
export NROFLAGS += --nacp=$(CURDIR)/$(DIST)/$(TARGET).nacp | |||
endif | |||
ifneq ($(APP_TITLEID),) | |||
export NACPFLAGS += --titleid=$(APP_TITLEID) | |||
endif | |||
ifneq ($(ROMFS),) | |||
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS) | |||
endif | |||
.PHONY: $(BUILD) clean all | |||
#--------------------------------------------------------------------------------- | |||
all: $(BUILD) | |||
$(BUILD): | |||
@[ -d $@ ] || mkdir -p $@ | |||
@[ -d $(DIST) ] || mkdir $(DIST) | |||
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile | |||
#--------------------------------------------------------------------------------- | |||
clean: | |||
@echo clean ... | |||
@rm -fr $(BUILD) $(DIST) | |||
#--------------------------------------------------------------------------------- | |||
else | |||
.PHONY: all | |||
DEPENDS := $(OFILES:.o=.d) | |||
#--------------------------------------------------------------------------------- | |||
# main targets | |||
#--------------------------------------------------------------------------------- | |||
all : $(OUTPUT).pfs0 $(OUTPUT).nro | |||
$(OUTPUT).pfs0 : $(OUTPUT).nso | |||
$(OUTPUT).nso : $(OUTPUT).elf | |||
ifeq ($(strip $(NO_NACP)),) | |||
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp | |||
else | |||
$(OUTPUT).nro : $(OUTPUT).elf | |||
endif | |||
$(OUTPUT).elf : $(OFILES) | |||
$(OFILES_SRC) : $(HFILES_BIN) | |||
#--------------------------------------------------------------------------------- | |||
# you need a rule like this for each extension you use as binary data | |||
#--------------------------------------------------------------------------------- | |||
%.bin.o %_bin.h : %.bin | |||
#--------------------------------------------------------------------------------- | |||
@echo $(notdir $<) | |||
@$(bin2o) | |||
-include $(DEPENDS) | |||
#--------------------------------------------------------------------------------------- | |||
endif | |||
#--------------------------------------------------------------------------------------- |
@ -0,0 +1,91 @@ | |||
// SDFile Updater | |||
// Copyright (C) 2018 Steven Mattera | |||
// | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License | |||
// as published by the Free Software Foundation; either version 2 | |||
// of the License, or (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
#include "ConfigManager.hpp" | |||
ConfigManager::ConfigManager() { | |||
config_init(&cfg); | |||
if(!config_read_file(&cfg, "settings.cfg")) { | |||
config_setting_t * root, * setting; | |||
root = config_root_setting(&cfg); | |||
setting = config_setting_add(root, "host", CONFIG_TYPE_STRING); | |||
config_setting_set_string(setting, "http://sdfu.stevenmattera.com"); | |||
setting = config_setting_add(root, "channel", CONFIG_TYPE_STRING); | |||
config_setting_set_string(setting, "stable"); | |||
setting = config_setting_add(root, "version", CONFIG_TYPE_STRING); | |||
config_setting_set_string(setting, ""); | |||
setting = config_setting_add(root, "launcher", CONFIG_TYPE_STRING); | |||
config_setting_set_string(setting, "Hekate"); | |||
config_write_file(&cfg, "settings.cfg"); | |||
} | |||
} | |||
ConfigManager::~ConfigManager() { | |||
config_destroy(&cfg); | |||
} | |||
std::string ConfigManager::getHost() { | |||
const char * str; | |||
if (!config_lookup_string(&cfg, "host", &str)) | |||
return "http://sdfu.stevenmattera.com"; | |||
return std::string(str); | |||
} | |||
std::string ConfigManager::getChannel() { | |||
const char * str; | |||
if (!config_lookup_string(&cfg, "channel", &str)) | |||
return "stable"; | |||
return std::string(str); | |||
} | |||
std::string ConfigManager::getCurrentVersion() { | |||
const char * str; | |||
if (!config_lookup_string(&cfg, "version", &str)) | |||
return ""; | |||
return std::string(str); | |||
} | |||
std::string ConfigManager::getLauncherPreference() { | |||
const char * str; | |||
if (!config_lookup_string(&cfg, "launcher", &str)) | |||
return "Hekate"; | |||
return std::string(str); | |||
} | |||
bool ConfigManager::writeCurrentVersion(std::string version) { | |||
config_setting_t * root, * setting; | |||
root = config_root_setting(&cfg); | |||
setting = config_setting_get_member(root, "version"); | |||
config_setting_set_string(setting, version.c_str()); | |||
return config_write_file(&cfg, "settings.cfg"); | |||
} |
@ -0,0 +1,34 @@ | |||
// SDFile Updater | |||
// Copyright (C) 2018 Steven Mattera | |||
// | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License | |||
// as published by the Free Software Foundation; either version 2 | |||
// of the License, or (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
#pragma once | |||
#include <libconfig.h> | |||
#include <string> | |||
class ConfigManager { | |||
public: | |||
config_t cfg; | |||
ConfigManager(); | |||
~ConfigManager(); | |||
std::string getHost(); | |||
std::string getChannel(); | |||
std::string getCurrentVersion(); | |||
std::string getLauncherPreference(); | |||
bool writeCurrentVersion(std::string version); | |||
}; |
@ -0,0 +1,28 @@ | |||
// SDFile Updater | |||
// Copyright (C) 2018 Steven Mattera | |||
// | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License | |||
// as published by the Free Software Foundation; either version 2 | |||
// of the License, or (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
#include "Download.hpp" | |||
#include <stdlib.h> | |||
Download::Download() { | |||
size = 0; | |||
data = (char *) malloc(1); | |||
} | |||
Download::~Download() { | |||
free(data); | |||
} |
@ -0,0 +1,29 @@ | |||
// SDFile Updater | |||
// Copyright (C) 2018 Steven Mattera | |||
// | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License | |||
// as published by the Free Software Foundation; either version 2 | |||
// of the License, or (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
#pragma once | |||
#include <string.h> | |||
class Download { | |||
public: | |||
size_t size; | |||
char * data; | |||
Download(); | |||
~Download(); | |||
}; |
@ -0,0 +1,102 @@ | |||
// SDFile Updater | |||
// Copyright (C) 2018 Steven Mattera | |||
// | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License | |||
// as published by the Free Software Foundation; either version 2 | |||
// of the License, or (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
#include "DownloadManager.hpp" | |||
#include <sys/socket.h> | |||
#include <curl/curl.h> | |||
#include <switch.h> | |||
DownloadManager::DownloadManager(std::string host) { | |||
socketInitializeDefault(); | |||
curl_global_init(CURL_GLOBAL_ALL); | |||
hostname = host; | |||
} | |||
DownloadManager::~DownloadManager() { | |||
curl_global_cleanup(); | |||
socketExit(); | |||
} | |||
Download * DownloadManager::getLatestVersion(std::string channel) { | |||
CURL *curl; | |||
CURLcode res; | |||
Download * download = new Download(); | |||
curl = curl_easy_init(); | |||
if (curl) { | |||
curl_easy_setopt(curl, CURLOPT_URL, (hostname + "/version-number/" + channel).c_str()); | |||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData); | |||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) download); | |||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "sdfile-updater/1.0"); | |||
res = curl_easy_perform(curl); | |||
if (res != CURLE_OK) { | |||
printf("! Failed to get latest version: %s\n", curl_easy_strerror(res)); | |||
delete download; | |||
download = NULL; | |||
} | |||
curl_easy_cleanup(curl); | |||
} | |||
return download; | |||
} | |||
Download * DownloadManager::getLatestFiles(std::string channel) { | |||
CURL *curl; | |||
CURLcode res; | |||
Download * download = new Download(); | |||
curl = curl_easy_init(); | |||
if (curl) { | |||
curl_easy_setopt(curl, CURLOPT_URL, (hostname + "/download/" + channel).c_str()); | |||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData); | |||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) download); | |||
curl_easy_setopt(curl, CURLOPT_USERAGENT, "sdfile-updater/1.0"); | |||
res = curl_easy_perform(curl); | |||
if (res != CURLE_OK) { | |||
printf("! Failed to get latest SD Files: %s\n", curl_easy_strerror(res)); | |||
delete download; | |||
download = NULL; | |||
} | |||
curl_easy_cleanup(curl); | |||
} | |||
return download; | |||
} | |||
size_t DownloadManager::writeData(void *contents, size_t size, size_t nmemb, void *userp) { | |||
size_t realsize = size * nmemb; | |||
Download * download = (Download *) userp; | |||
download->data = (char *) realloc(download->data, download->size + realsize + 1); | |||
if (download->data == NULL) { | |||
printf("! Not enough memory.\n"); | |||
return 0; | |||
} | |||
memcpy(&(download->data[download->size]), contents, realsize); | |||
download->size += realsize; | |||
download->data[download->size] = 0; | |||
return realsize; | |||
} |
@ -0,0 +1,34 @@ | |||
// SDFile Updater | |||
// Copyright (C) 2018 Steven Mattera | |||
// | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License | |||
// as published by the Free Software Foundation; either version 2 | |||
// of the License, or (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
#pragma once | |||
#include <string> | |||
#include "Download.hpp" | |||
class DownloadManager { | |||
public: | |||
DownloadManager(std::string host); | |||
~DownloadManager(); | |||
Download * getLatestVersion(std::string channel); | |||
Download * getLatestFiles(std::string channel); | |||
private: | |||
std::string hostname; | |||
static size_t writeData(void *contents, size_t size, size_t nmemb, void *userp); | |||
}; |
@ -0,0 +1,40 @@ | |||
#include <sys/stat.h> | |||
#include "Utils.hpp" | |||
bool CreateSubfolder(char* cpath) | |||
{ | |||
std::string path(cpath); | |||
return mkpath(path); | |||
} | |||
// http://stackoverflow.com/a/11366985 | |||
bool mkpath( std::string path ) | |||
{ | |||
bool bSuccess = false; | |||
int nRC = ::mkdir(path.c_str(), 0775); | |||
if(nRC == -1) | |||
{ | |||
switch(errno) | |||
{ | |||
case ENOENT: | |||
//parent didn't exist, try to create it | |||
if( mkpath(path.substr(0, path.find_last_of('/')))) | |||
//Now, try to create again. | |||
bSuccess = 0 == ::mkdir(path.c_str(), 0775); | |||
else | |||
bSuccess = false; | |||
break; | |||
case EEXIST: | |||
//Done! | |||
bSuccess = true; | |||
break;std::string getHost(); | |||
default: | |||
bSuccess = false; | |||
break; | |||
} | |||
} | |||
else | |||
bSuccess = true; | |||
return bSuccess; | |||
} |
@ -0,0 +1,8 @@ | |||
#pragma once | |||
#include <stdio.h> | |||
#include <string> | |||
// folder stuff | |||
bool mkpath( std::string path ); | |||
bool CreateSubfolder( char* cstringpath ); |
@ -0,0 +1,183 @@ | |||
// Copyright 2016 Zarklord1 : https://github.com/Zarklord1/WiiU_Save_Manager | |||
#include <string.h> | |||
#include <fcntl.h> | |||
#include <string> | |||
#include <dirent.h> | |||
#include <stdio.h> | |||
#include <cstdint> | |||
#include <unistd.h> | |||
#include "ZipUtil.hpp" | |||
#include "Utils.hpp" | |||
#define u32 uint32_t | |||
#define u8 uint8_t | |||
using namespace std; | |||
UnZip::UnZip(const char * zipPath) { | |||
fileToUnzip = unzOpen(zipPath); | |||
} | |||
UnZip::~UnZip() { | |||
Close(); | |||
} | |||
void UnZip::Close() { | |||
unzClose(fileToUnzip); | |||
} | |||
int UnZip::ExtractFile(const char * internalPath,const char * path) { | |||
int code = unzLocateFile(fileToUnzip,internalPath,0); | |||
if(code == UNZ_END_OF_LIST_OF_FILE) | |||
return -1; | |||
unz_file_info_s * fileInfo = GetFileInfo(); | |||
std::string fullPath(path); | |||
code = Extract(fullPath.c_str(),fileInfo); | |||
free(fileInfo); | |||
return code; | |||
} | |||
int UnZip::ExtractDir(const char * internalDir,const char * externalDir) { | |||
int i = 0; | |||
for(;;) { | |||
int code; | |||
if(i == 0) { | |||
code = unzGoToFirstFile(fileToUnzip); | |||
i++; | |||
} else { | |||
code = unzGoToNextFile(fileToUnzip); | |||
} | |||
if(code == UNZ_END_OF_LIST_OF_FILE) { | |||
if(i > 1) { | |||
return 0; | |||
} else { | |||
return -1; | |||
} | |||
} | |||
unz_file_info_s * fileInfo = GetFileInfo(); | |||
std::string outputPath = GetFullFileName(fileInfo); | |||
if(outputPath.find(internalDir,0) != 0) { | |||
free(fileInfo); | |||
continue; | |||
} | |||
outputPath.replace(0,strlen(internalDir),externalDir); | |||
if(fileInfo->uncompressed_size != 0 && fileInfo->compression_method != 0) { | |||
i++; | |||
Extract(outputPath.c_str(),fileInfo); | |||
} | |||
free(fileInfo); | |||
} | |||
} | |||
int UnZip::ExtractAll(const char * dirToExtract) { | |||
int i = 0; | |||
for(;;) { | |||
int code; | |||
if(i == 0) { | |||
code = unzGoToFirstFile(fileToUnzip); | |||
i++; | |||
} else { | |||
code = unzGoToNextFile(fileToUnzip); | |||
} | |||
if(code == UNZ_END_OF_LIST_OF_FILE) return 0; | |||
unz_file_info_s * fileInfo = GetFileInfo(); | |||
std::string fileName(dirToExtract); | |||
fileName += '/'; | |||
fileName += GetFullFileName(fileInfo); | |||
if(fileInfo->uncompressed_size != 0 && fileInfo->compression_method != 0) { | |||
Extract(fileName.c_str(),fileInfo); | |||
} | |||
free(fileInfo); | |||
} | |||
} | |||
int UnZip::Extract(const char * path, unz_file_info_s * fileInfo) { | |||
//check to make sure filepath or fileInfo isnt null | |||
if(path == NULL || fileInfo == NULL) | |||
return -1; | |||
if(unzOpenCurrentFile(fileToUnzip) != UNZ_OK) | |||
return -2; | |||
char folderPath[strlen(path)+1]; | |||
strcpy(folderPath,path); | |||
char * pos = strrchr(folderPath,'/'); | |||
if(pos != NULL) { | |||
*pos = '\0'; | |||
CreateSubfolder(folderPath); | |||
} | |||
u32 blocksize = 0x8000; | |||
u8 * buffer = (u8*)malloc(blocksize); | |||
if(buffer == NULL) | |||
return -3; | |||
u32 done = 0; | |||
int writeBytes = 0; | |||
FILE* fp = fopen(path, "w"); | |||
if(fp == NULL) { | |||
free(buffer); | |||
return -4; | |||
} | |||
while(done < fileInfo->uncompressed_size) | |||
{ | |||
if(done + blocksize > fileInfo->uncompressed_size) { | |||
blocksize = fileInfo->uncompressed_size - done; | |||
} | |||
unzReadCurrentFile(fileToUnzip, buffer, blocksize); | |||
writeBytes = write(fileno(fp), buffer, blocksize); | |||
if(writeBytes <= 0) { | |||
break; | |||
} | |||
done += writeBytes; | |||
} | |||
fflush(fp); | |||
fclose(fp); | |||
free(buffer); | |||
if (done != fileInfo->uncompressed_size) | |||
return -4; | |||
unzCloseCurrentFile(fileToUnzip); | |||
return 0; | |||
} | |||
std::string UnZip::GetFileName(unz_file_info_s * fileInfo) { | |||
char fileName[fileInfo->size_filename+1]; | |||
std::string path; | |||
strcpy(fileName,GetFullFileName(fileInfo).c_str()); | |||
char * pos = strrchr(fileName, '/'); | |||
if (pos != NULL) { | |||
pos++; | |||
path = pos; | |||
} else { | |||
path = fileName; | |||
} | |||
return path; | |||
} | |||
std::string UnZip::GetFullFileName(unz_file_info_s * fileInfo) { | |||
char filePath[fileInfo->size_filename+1]; | |||
unzGetCurrentFileInfo(fileToUnzip,fileInfo,filePath,fileInfo->size_filename,NULL,0,NULL,0); | |||
filePath[fileInfo->size_filename] = '\0'; | |||
std::string path(filePath); | |||
path.resize(fileInfo->size_filename); | |||
return path; | |||
} | |||
unz_file_info_s * UnZip::GetFileInfo() { | |||
unz_file_info_s * fileInfo = (unz_file_info_s*)malloc(sizeof(unz_file_info_s)); | |||
unzGetCurrentFileInfo(fileToUnzip,fileInfo,NULL,0,NULL,0,NULL,0); | |||
return fileInfo; | |||
} |
@ -0,0 +1,24 @@ | |||
#pragma once | |||
// use included minizip library | |||
#include "minizip/unzip.h" | |||
#include <string> | |||
class UnZip { | |||
public: | |||
unzFile fileToUnzip; | |||
UnZip(const char * zipPath); | |||
~UnZip(); | |||
void Close(); | |||
int ExtractFile(const char * internalPath,const char * path); | |||
int ExtractAll(const char * dirToExtract); | |||
int ExtractDir(const char * internalDir,const char * externalDir); | |||
std::string GetFullFileName(unz_file_info_s * fileInfo); | |||
unz_file_info_s * GetFileInfo(); | |||
private: | |||
int Extract(const char * path, unz_file_info_s * fileInfo); | |||
std::string GetFileName(unz_file_info_s * fileInfo); | |||
}; | |||
@ -0,0 +1,160 @@ | |||
// SDFile Updater | |||
// Copyright (C) 2018 Steven Mattera | |||
// | |||
// This program is free software; you can redistribute it and/or | |||
// modify it under the terms of the GNU General Public License | |||
// as published by the Free Software Foundation; either version 2 | |||
// of the License, or (at your option) any later version. | |||
// | |||
// This program is distributed in the hope that it will be useful, | |||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
// GNU General Public License for more details. | |||
// | |||
// You should have received a copy of the GNU General Public License | |||
// along with this program; if not, write to the Free Software | |||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
#include <string.h> | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include <switch.h> | |||
#include "DownloadManager.hpp" | |||
#include "ConfigManager.hpp" | |||
#include "ZipUtil.hpp" | |||
using namespace std; | |||
bool writeFile(std::string filename, Download * download); | |||
bool deleteFile(std::string filename); | |||
bool fileExists(std::string filename); | |||
int main(int argc, char **argv) | |||
{ | |||
gfxInitDefault(); | |||
consoleInit(NULL); | |||
ConfigManager * configManager = new ConfigManager(); | |||
DownloadManager * downloadManager = new DownloadManager(configManager->getHost()); | |||
printf("SDFile Updater version 1.0.0\n\n"); | |||
bool downloadSDFiles = false; | |||
string version = configManager->getCurrentVersion(); | |||
string channel = configManager->getChannel(); | |||
Download * latestVersion = downloadManager->getLatestVersion(channel); | |||
if (version.empty()) { | |||
printf("- Unknown version currently installed.\n"); | |||
downloadSDFiles = true; | |||
} else if (latestVersion != NULL) { | |||
if (version.compare(std::string(latestVersion->data)) == 0) { | |||
printf("- SD files are already up to date!\n"); | |||
delete latestVersion; | |||
} else { | |||
downloadSDFiles = true; | |||
} | |||
} | |||
if (downloadSDFiles) { | |||
printf("- Downloading latest SD files...\n"); | |||
Download * latestFile = downloadManager->getLatestFiles(channel); | |||
if (latestFile != NULL) { | |||
printf("- Latest SD files downloaded!\n"); | |||
writeFile("latest.zip", latestFile); | |||
delete latestFile; | |||
UnZip * zip = new UnZip("latest.zip"); | |||
std::string launcher = configManager->getLauncherPreference(); | |||
int i = 0; | |||
for(;;) { | |||
int code; | |||
if(i == 0) { | |||
code = unzGoToFirstFile(zip->fileToUnzip); | |||
i++; | |||
} else { | |||
code = unzGoToNextFile(zip->fileToUnzip); | |||
} | |||
if(code == UNZ_END_OF_LIST_OF_FILE) | |||
break; | |||
unz_file_info_s * fileInfo = zip->GetFileInfo(); | |||
std::string internalFileName = zip->GetFullFileName(fileInfo); | |||
if(fileInfo->uncompressed_size != 0 && fileInfo->compression_method != 0) { | |||
if (internalFileName.compare(0, launcher.length(), launcher) == 0) { | |||
std::string externalFileName = "sdmc:/" + std::string(internalFileName).substr(launcher.length() + 1, internalFileName.length() - (launcher.length() + 1)); | |||
zip->ExtractFile(internalFileName.c_str(), externalFileName.c_str()); | |||
} | |||
} | |||
free(fileInfo); | |||
} | |||
delete zip; | |||
deleteFile("latest.zip"); | |||
printf("- Installed %s SD Files!\n", latestVersion->data); | |||
configManager->writeCurrentVersion(std::string(latestVersion->data)); | |||
delete latestVersion; | |||
} | |||
} | |||
printf("\nPress any button to exit.\n"); | |||
gfxFlushBuffers(); | |||
gfxSwapBuffers(); | |||
gfxWaitForVsync(); | |||
while(appletMainLoop()) | |||
{ | |||
hidScanInput(); | |||
if (hidKeysDown(CONTROLLER_P1_AUTO) >= 1) { | |||
break; | |||
} | |||
} | |||
delete configManager; | |||
delete downloadManager; | |||
gfxExit(); | |||
return 0; | |||
} | |||
/* Helper Functions */ | |||
bool writeFile(std::string filename, Download * download) { | |||
deleteFile(filename); | |||
FILE * file = fopen(filename.c_str(), "w"); | |||
if (!file) { | |||
return false; | |||
} | |||
size_t result = fwrite(download->data, sizeof(char), download->size, file); | |||
fclose(file); | |||
return (result == download->size); | |||
} | |||
bool deleteFile(std::string filename) { | |||
if (fileExists(filename)) { | |||
return remove(filename.c_str()) == 0; | |||
} | |||
return false; | |||
} | |||
bool fileExists(std::string filename) { | |||
FILE * file = fopen(filename.c_str(), "r"); | |||
if (file) { | |||
fclose(file); | |||
return true; | |||
} | |||
return false; | |||
} |
@ -0,0 +1,247 @@ | |||
/* ioapi.h -- IO base function header for compress/uncompress .zip | |||
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) | |||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) | |||
Modifications for Zip64 support | |||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) | |||
For more info read MiniZip_info.txt | |||
*/ | |||
#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS))) | |||
#define _CRT_SECURE_NO_WARNINGS | |||
#endif | |||
#if defined(__APPLE__) || defined(IOAPI_NO_64) | |||
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions | |||
#define FOPEN_FUNC(filename, mode) fopen(filename, mode) | |||
#define FTELLO_FUNC(stream) ftello(stream) | |||
#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) | |||
#else | |||
#define FOPEN_FUNC(filename, mode) fopen64(filename, mode) | |||
#define FTELLO_FUNC(stream) ftello64(stream) | |||
#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) | |||
#endif | |||
#include "ioapi.h" | |||
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode) | |||
{ | |||
if (pfilefunc->zfile_func64.zopen64_file != NULL) | |||
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode); | |||
else | |||
{ | |||
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode); | |||
} | |||
} | |||
long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin) | |||
{ | |||
if (pfilefunc->zfile_func64.zseek64_file != NULL) | |||
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin); | |||
else | |||
{ | |||
uLong offsetTruncated = (uLong)offset; | |||
if (offsetTruncated != offset) | |||
return -1; | |||
else | |||
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin); | |||
} | |||
} | |||
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream) | |||
{ | |||
if (pfilefunc->zfile_func64.zseek64_file != NULL) | |||
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream); | |||
else | |||
{ | |||
uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream); | |||
if ((tell_uLong) == MAXU32) | |||
return (ZPOS64_T)-1; | |||
else | |||
return tell_uLong; | |||
} | |||
} | |||
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32) | |||
{ | |||
p_filefunc64_32->zfile_func64.zopen64_file = NULL; | |||
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; | |||
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; | |||
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file; | |||
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file; | |||
p_filefunc64_32->zfile_func64.ztell64_file = NULL; | |||
p_filefunc64_32->zfile_func64.zseek64_file = NULL; | |||
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file; | |||
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file; | |||
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque; | |||
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file; | |||
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file; | |||
} | |||
static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode)); | |||
static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); | |||
static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size)); | |||
static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream)); | |||
static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); | |||
static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream)); | |||
static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream)); | |||
static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode) | |||
{ | |||
FILE* file = NULL; | |||
const char* mode_fopen = NULL; | |||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) | |||
mode_fopen = "rb"; | |||
else | |||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING) | |||
mode_fopen = "r+b"; | |||
else | |||
if (mode & ZLIB_FILEFUNC_MODE_CREATE) | |||
mode_fopen = "wb"; | |||
if ((filename!=NULL) && (mode_fopen != NULL)) | |||
file = fopen(filename, mode_fopen); | |||
return file; | |||
} | |||
static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode) | |||
{ | |||
FILE* file = NULL; | |||
const char* mode_fopen = NULL; | |||
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) | |||
mode_fopen = "rb"; | |||
else | |||
if (mode & ZLIB_FILEFUNC_MODE_EXISTING) | |||
mode_fopen = "r+b"; | |||
else | |||
if (mode & ZLIB_FILEFUNC_MODE_CREATE) | |||
mode_fopen = "wb"; | |||
if ((filename!=NULL) && (mode_fopen != NULL)) | |||
file = FOPEN_FUNC((const char*)filename, mode_fopen); | |||
return file; | |||
} | |||
static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) | |||
{ | |||
uLong ret; | |||
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); | |||
return ret; | |||
} | |||
static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) | |||
{ | |||
uLong ret; | |||
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); | |||
return ret; | |||
} | |||
static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) | |||
{ | |||
long ret; | |||
ret = ftell((FILE *)stream); | |||
return ret; | |||
} | |||
static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) | |||
{ | |||
ZPOS64_T ret; | |||
ret = FTELLO_FUNC((FILE *)stream); | |||
return ret; | |||
} | |||
static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) | |||
{ | |||
int fseek_origin=0; | |||
long ret; | |||
switch (origin) | |||
{ | |||
case ZLIB_FILEFUNC_SEEK_CUR : | |||
fseek_origin = SEEK_CUR; | |||
break; | |||
case ZLIB_FILEFUNC_SEEK_END : | |||
fseek_origin = SEEK_END; | |||
break; | |||
case ZLIB_FILEFUNC_SEEK_SET : | |||
fseek_origin = SEEK_SET; | |||
break; | |||
default: return -1; | |||
} | |||
ret = 0; | |||
if (fseek((FILE *)stream, offset, fseek_origin) != 0) | |||
ret = -1; | |||
return ret; | |||
} | |||
static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) | |||
{ | |||
int fseek_origin=0; | |||
long ret; | |||
switch (origin) | |||
{ | |||
case ZLIB_FILEFUNC_SEEK_CUR : | |||
fseek_origin = SEEK_CUR; | |||
break; | |||
case ZLIB_FILEFUNC_SEEK_END : | |||
fseek_origin = SEEK_END; | |||
break; | |||
case ZLIB_FILEFUNC_SEEK_SET : | |||
fseek_origin = SEEK_SET; | |||
break; | |||
default: return -1; | |||
} | |||
ret = 0; | |||
if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0) | |||
ret = -1; | |||
return ret; | |||
} | |||
static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) | |||
{ | |||
int ret; | |||
ret = fclose((FILE *)stream); | |||
return ret; | |||
} | |||
static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream) | |||
{ | |||
int ret; | |||
ret = ferror((FILE *)stream); | |||
return ret; | |||
} | |||
void fill_fopen_filefunc (pzlib_filefunc_def) | |||
zlib_filefunc_def* pzlib_filefunc_def; | |||
{ | |||
pzlib_filefunc_def->zopen_file = fopen_file_func; | |||
pzlib_filefunc_def->zread_file = fread_file_func; | |||
pzlib_filefunc_def->zwrite_file = fwrite_file_func; | |||
pzlib_filefunc_def->ztell_file = ftell_file_func; | |||
pzlib_filefunc_def->zseek_file = fseek_file_func; | |||
pzlib_filefunc_def->zclose_file = fclose_file_func; | |||
pzlib_filefunc_def->zerror_file = ferror_file_func; | |||
pzlib_filefunc_def->opaque = NULL; | |||
} | |||
void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def) | |||
{ | |||
pzlib_filefunc_def->zopen64_file = fopen64_file_func; | |||
pzlib_filefunc_def->zread_file = fread_file_func; | |||
pzlib_filefunc_def->zwrite_file = fwrite_file_func; | |||
pzlib_filefunc_def->ztell64_file = ftell64_file_func; | |||
pzlib_filefunc_def->zseek64_file = fseek64_file_func; | |||
pzlib_filefunc_def->zclose_file = fclose_file_func; | |||
pzlib_filefunc_def->zerror_file = ferror_file_func; | |||
pzlib_filefunc_def->opaque = NULL; | |||
} |
@ -0,0 +1,208 @@ | |||
/* ioapi.h -- IO base function header for compress/uncompress .zip | |||
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) | |||
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) | |||
Modifications for Zip64 support | |||
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) | |||
For more info read MiniZip_info.txt | |||
Changes | |||
Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this) | |||
Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. | |||
More if/def section may be needed to support other platforms | |||
Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. | |||
(but you should use iowin32.c for windows instead) | |||
*/ | |||
#ifndef _ZLIBIOAPI64_H | |||
#define _ZLIBIOAPI64_H | |||
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) | |||
// Linux needs this to support file operation on files larger then 4+GB | |||
// But might need better if/def to select just the platforms that needs them. | |||
#ifndef __USE_FILE_OFFSET64 | |||
#define __USE_FILE_OFFSET64 | |||
#endif | |||
#ifndef __USE_LARGEFILE64 | |||
#define __USE_LARGEFILE64 | |||
#endif | |||
#ifndef _LARGEFILE64_SOURCE | |||
#define _LARGEFILE64_SOURCE | |||
#endif | |||
#ifndef _FILE_OFFSET_BIT | |||
#define _FILE_OFFSET_BIT 64 | |||
#endif | |||
#endif | |||
#include <stdio.h> | |||
#include <stdlib.h> | |||
#include "zlib.h" | |||
#if defined(USE_FILE32API) | |||
#define fopen64 fopen | |||
#define ftello64 ftell | |||
#define fseeko64 fseek | |||
#else | |||
#ifdef __FreeBSD__ | |||
#define fopen64 fopen | |||
#define ftello64 ftello | |||
#define fseeko64 fseeko | |||
#endif | |||
#ifdef _MSC_VER | |||
#define fopen64 fopen | |||
#if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) | |||
#define ftello64 _ftelli64 | |||
#define fseeko64 _fseeki64 | |||
#else // old MSC | |||
#define ftello64 ftell | |||
#define fseeko64 fseek | |||
#endif | |||
#endif | |||
#endif | |||
/* | |||
#ifndef ZPOS64_T | |||
#ifdef _WIN32 | |||
#define ZPOS64_T fpos_t | |||
#else | |||
#include <stdint.h> | |||
#define ZPOS64_T uint64_t | |||
#endif | |||
#endif | |||
*/ | |||
#ifdef HAVE_MINIZIP64_CONF_H | |||
#include "mz64conf.h" | |||
#endif | |||
/* a type choosen by DEFINE */ | |||
#ifdef HAVE_64BIT_INT_CUSTOM | |||
typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; | |||
#else | |||
#ifdef HAS_STDINT_H | |||
#include "stdint.h" | |||
typedef uint64_t ZPOS64_T; | |||
#else | |||
/* Maximum unsigned 32-bit value used as placeholder for zip64 */ | |||
#define MAXU32 0xffffffff | |||
#if defined(_MSC_VER) || defined(__BORLANDC__) | |||
typedef unsigned __int64 ZPOS64_T; | |||
#else | |||
typedef unsigned long long int ZPOS64_T; | |||
#endif | |||
#endif | |||
#endif | |||
#ifdef __cplusplus | |||
extern "C" { | |||
#endif | |||
#define ZLIB_FILEFUNC_SEEK_CUR (1) | |||
#define ZLIB_FILEFUNC_SEEK_END (2) | |||
#define ZLIB_FILEFUNC_SEEK_SET (0) | |||
#define ZLIB_FILEFUNC_MODE_READ (1) | |||
#define ZLIB_FILEFUNC_MODE_WRITE (2) | |||
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) | |||
#define ZLIB_FILEFUNC_MODE_EXISTING (4) | |||
#define ZLIB_FILEFUNC_MODE_CREATE (8) | |||
#ifndef ZCALLBACK | |||
#if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) | |||
#define ZCALLBACK CALLBACK | |||
#else | |||
#define ZCALLBACK | |||
#endif | |||
#endif | |||
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); | |||
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); | |||
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); | |||
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); | |||
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); | |||
typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); | |||
typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); | |||
/* here is the "old" 32 bits structure structure */ | |||
typedef struct zlib_filefunc_def_s | |||
{ | |||
open_file_func zopen_file; | |||
read_file_func zread_file; | |||
write_file_func zwrite_file; | |||
tell_file_func ztell_file; | |||
seek_file_func zseek_file; | |||
close_file_func zclose_file; | |||
testerror_file_func zerror_file; | |||
voidpf opaque; | |||
} zlib_filefunc_def; | |||
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); | |||
typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); | |||
typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); | |||
typedef struct zlib_filefunc64_def_s | |||
{ | |||
open64_file_func zopen64_file; | |||
read_file_func zread_file; | |||
write_file_func zwrite_file; | |||
tell64_file_func ztell64_file; | |||
seek64_file_func zseek64_file; | |||
close_file_func zclose_file; | |||
testerror_file_func zerror_file; | |||
voidpf opaque; | |||
} zlib_filefunc64_def; | |||
void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); | |||
void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); | |||
/* now internal definition, only for zip.c and unzip.h */ | |||
typedef struct zlib_filefunc64_32_def_s | |||
{ | |||
zlib_filefunc64_def zfile_func64; | |||
open_file_func zopen32_file; | |||
tell_file_func ztell32_file; | |||
seek_file_func zseek32_file; | |||
} zlib_filefunc64_32_def; | |||
#define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) | |||
#define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) | |||
//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) | |||
//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) | |||
#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) | |||
#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) | |||
voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); | |||
long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); | |||
ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); | |||
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); | |||