Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
5e583dd3
Commit
5e583dd3
authored
Jul 06, 2007
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an option to create an installer package.
parent
aa9de1c3
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
163 additions
and
24 deletions
+163
-24
src/data/installer.cpp
src/data/installer.cpp
+66
-0
src/data/installer.hpp
src/data/installer.hpp
+8
-1
src/main.cpp
src/main.cpp
+61
-4
src/resource/msw/icon/installer.ico
src/resource/msw/icon/installer.ico
+0
-0
src/resource/msw/mse.rc
src/resource/msw/mse.rc
+1
-3
src/util/io/package.cpp
src/util/io/package.cpp
+20
-12
src/util/io/package.hpp
src/util/io/package.hpp
+7
-4
No files found.
src/data/installer.cpp
View file @
5e583dd3
...
...
@@ -7,7 +7,11 @@
// ----------------------------------------------------------------------------- : Includes
#include <data/installer.hpp>
#include <util/io/package_manager.hpp>
#include <script/to_value.hpp>
#include <wx/filename.h>
DECLARE_TYPEOF_COLLECTION
(
String
);
// ----------------------------------------------------------------------------- : Installer
...
...
@@ -17,3 +21,65 @@ IMPLEMENT_REFLECTION(Installer) {
REFLECT_BASE
(
Packaged
);
REFLECT
(
packages
);
}
// ----------------------------------------------------------------------------- : Installing
void
Installer
::
installFrom
(
const
String
&
filename
,
bool
message_on_success
)
{
Installer
i
;
i
.
open
(
filename
);
i
.
install
();
if
(
message_on_success
)
{
wxMessageBox
(
String
::
Format
(
_
(
"'%s' successfully installed %d package%s."
),
i
.
name
(),
i
.
packages
.
size
(),
i
.
packages
.
size
()
==
1
?
_
(
""
)
:
_
(
"s"
)),
_
(
"Magic Set Editor"
),
wxOK
|
wxICON_INFORMATION
);
}
}
void
Installer
::
install
()
{
// Walk over all files in this installer
const
FileInfos
&
file_infos
=
getFileInfos
();
for
(
FileInfos
::
const_iterator
it
=
file_infos
.
begin
()
;
it
!=
file_infos
.
end
()
;
++
it
)
{
// const String& filename = it->first;
//
}
// REMOVE?
FOR_EACH
(
p
,
packages
)
{
install
(
p
);
}
}
void
Installer
::
install
(
const
String
&
package
)
{
// 1. Make sure the package is not loaded
// TODO
}
// ----------------------------------------------------------------------------- : Creating
void
Installer
::
addPackage
(
const
String
&
package
)
{
wxFileName
fn
(
package
);
if
(
fn
.
GetExt
()
==
_
(
".mse-installer"
))
{
prefered_filename
=
package
;
}
else
{
PackagedP
p
=
::
packages
.
openAny
(
package
);
addPackage
(
*
p
);
}
}
void
Installer
::
addPackage
(
Packaged
&
package
)
{
// Add to list of packages
String
name
=
package
.
relativeFilename
();
if
(
find
(
packages
.
begin
(),
packages
.
end
(),
package
.
name
())
!=
packages
.
end
())
{
return
;
// already added
}
if
(
prefered_filename
.
empty
())
{
prefered_filename
=
package
.
name
()
+
_
(
".mse-installer"
);
}
packages
.
push_back
(
name
);
// Copy all files from that package to this one
const
FileInfos
&
file_infos
=
package
.
getFileInfos
();
for
(
FileInfos
::
const_iterator
it
=
file_infos
.
begin
()
;
it
!=
file_infos
.
end
()
;
++
it
)
{
String
file
=
it
->
first
;
InputStreamP
is
=
package
.
openIn
(
file
);
OutputStreamP
os
=
openOut
(
name
+
_
(
"/"
)
+
file
);
os
->
Write
(
*
is
);
}
}
src/data/installer.hpp
View file @
5e583dd3
...
...
@@ -20,13 +20,20 @@ class Installer : public Packaged {
String
prefered_filename
;
///< What filename should be used (by default)
vector
<
String
>
packages
;
///< Packages to install
/// Load an installer from a file, and run it
static
void
installFrom
(
const
String
&
filename
,
bool
message_on_success
);
/// Install all the packages
void
install
();
/// Install a specific package
void
install
(
const
String
&
package
);
/// Add a package to the installer (if it is not already added).
/** If the package is named *.mse-installer uses it as the filename instead */
void
addPackage
(
const
String
&
package
);
/// Add a package to the installer (if it is not already added).
/** The first package gives the name of the installer.
*/
void
addPackage
(
const
Packaged
&
package
);
void
addPackage
(
Packaged
&
package
);
protected:
String
typeName
()
const
;
...
...
src/main.cpp
View file @
5e583dd3
...
...
@@ -12,6 +12,7 @@
#include <data/set.hpp>
#include <data/settings.hpp>
#include <data/locale.hpp>
#include <data/installer.hpp>
#include <data/format/formats.hpp>
#include <gui/welcome_window.hpp>
#include <gui/update_checker.hpp>
...
...
@@ -19,6 +20,8 @@
#include <gui/symbol/window.hpp>
#include <gui/thumbnail_thread.hpp>
#include <wx/fs_inet.h>
#include <wx/wfstream.h>
#include <wx/txtstrm.h>
// ----------------------------------------------------------------------------- : Main function/class
...
...
@@ -37,6 +40,24 @@ class MSE : public wxApp {
IMPLEMENT_APP
(
MSE
)
// ----------------------------------------------------------------------------- : GUI/Console
/// Write a message to the console if it is available, and to a message box otherwise
void
write_stdout
(
const
String
&
str
)
{
bool
have_console
=
false
;
#ifndef __WXMSW__
// somehow detect whether to use console output
#endif
if
(
have_console
)
{
wxFileOutputStream
file
(
wxFile
::
fd_stdout
);
wxTextOutputStream
t
(
file
);
t
.
WriteString
(
str
);
}
else
{
// no console, use a message box
wxMessageBox
(
str
,
_
(
"Magic Set Editor"
),
wxOK
|
wxICON_INFORMATION
);
}
}
// ----------------------------------------------------------------------------- : Initialization
bool
MSE
::
OnInit
()
{
...
...
@@ -59,6 +80,7 @@ bool MSE::OnInit() {
if
(
argc
>
1
)
{
try
{
// Command line argument, find its extension
String
arg
=
argv
[
1
];
wxFileName
f
(
argv
[
1
]);
if
(
f
.
GetExt
()
==
_
(
"mse-symbol"
))
{
// Show the symbol editor
...
...
@@ -70,6 +92,41 @@ bool MSE::OnInit() {
Window
*
wnd
=
new
SetWindow
(
nullptr
,
import_set
(
argv
[
1
]));
wnd
->
Show
();
return
true
;
}
else
if
(
f
.
GetExt
()
==
_
(
"mse-installer"
))
{
// Installer; install it
Installer
::
installFrom
(
argv
[
1
],
true
);
return
false
;
}
else
if
(
arg
==
_
(
"--create-installer"
))
{
// create an installer
Installer
inst
;
for
(
int
i
=
2
;
i
<
argc
;
++
i
)
{
inst
.
addPackage
(
argv
[
i
]);
}
if
(
inst
.
prefered_filename
.
empty
())
{
throw
Error
(
_
(
"Specify packages to include in installer"
));
}
else
{
inst
.
saveAs
(
inst
.
prefered_filename
,
false
);
}
return
false
;
}
else
if
(
arg
==
_
(
"--help"
)
||
arg
==
_
(
"-?"
))
{
// command line help
write_stdout
(
String
(
_
(
"Magic Set Editor
\n\n
"
))
+
_
(
"Usage: "
)
+
argv
[
0
]
+
_
(
"[OPTIONS]
\n\n
"
)
+
_
(
" no options
\t
Start the MSE user interface showing the welcome window.
\n
"
)
+
_
(
" FILE.mse-set,
\n
"
)
+
_
(
" FILE.set,
\n
"
)
+
_
(
" FILE.mse
\t
Load the set file in the MSE user interface.
\n
"
)
+
_
(
" FILE.mse-symbol
\t
Load the symbol into the MSE symbol editor.
\n
"
)
+
_
(
" FILE.mse-installer
\t
Install the packages from the installer.
\n
"
)
+
_
(
" -? --help
\t
Shows this help screen.
\n
"
)
+
_
(
" -v --version
\t
Show version information.
\n
"
)
+
_
(
" --create-installer
\n
"
)
+
_
(
" FILE [FILE]...
\t
Create an instaler named FILE, containing the listed packges.
\n
"
)
);
return
false
;
}
else
if
(
arg
==
_
(
"--version"
)
||
arg
==
_
(
"-v"
))
{
// dump version
write_stdout
(
_
(
"Magic Set Editor
\n
Version "
)
+
app_version
.
toString
()
+
version_suffix
);
return
false
;
}
else
{
handle_error
(
_
(
"Invalid command line argument:
\n
"
)
+
String
(
argv
[
1
]));
}
...
...
@@ -82,9 +139,9 @@ bool MSE::OnInit() {
(
new
WelcomeWindow
())
->
Show
();
return
true
;
}
catch
(
Error
e
)
{
}
catch
(
const
Error
&
e
)
{
handle_error
(
e
,
false
);
}
catch
(
std
::
exception
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
// we don't throw std::exception ourselfs, so this is probably something serious
handle_error
(
InternalError
(
String
(
e
.
what
(),
IF_UNICODE
(
wxConvLocal
,
wxSTRING_MAXLEN
)
)),
false
);
}
catch
(...)
{
...
...
@@ -108,9 +165,9 @@ int MSE::OnExit() {
bool
MSE
::
OnExceptionInMainLoop
()
{
try
{
throw
;
// rethrow the exception, so we can examine it
}
catch
(
Error
e
)
{
}
catch
(
const
Error
&
e
)
{
handle_error
(
e
,
false
);
}
catch
(
std
::
exception
e
)
{
}
catch
(
const
std
::
exception
&
e
)
{
// we don't throw std::exception ourselfs, so this is probably something serious
handle_error
(
InternalError
(
String
(
e
.
what
(),
IF_UNICODE
(
wxConvLocal
,
wxSTRING_MAXLEN
)
)),
false
);
}
catch
(...)
{
...
...
src/resource/msw/icon/installer.ico
0 → 100644
View file @
5e583dd3
5.1 KB
src/resource/msw/mse.rc
View file @
5e583dd3
...
...
@@ -9,10 +9,8 @@
// -------------------------------------------------------- : Icons
icon/app ICON "icon/app.ico" // has to come first in alphabet!!
icon/export ICON "icon/set.ico" //todo
icon/game ICON "icon/set.ico" //todo
icon/installer ICON "icon/installer.ico"
icon/set ICON "icon/set.ico"
icon/style ICON "icon/set.ico" //todo
icon/symbol ICON "icon/symbol.ico"
// -------------------------------------------------------- : Toolbar
...
...
src/util/io/package.cpp
View file @
5e583dd3
...
...
@@ -56,6 +56,11 @@ String Package::name() const {
else
if
(
ext
==
String
::
npos
)
return
filename
.
substr
(
slash
+
1
);
else
return
filename
.
substr
(
slash
+
1
,
ext
-
slash
-
1
);
}
String
Package
::
relativeFilename
()
const
{
size_t
slash
=
filename
.
find_last_of
(
_
(
"/
\\
:"
));
if
(
slash
==
String
::
npos
)
return
filename
;
else
return
filename
.
substr
(
slash
+
1
);
}
const
String
&
Package
::
absoluteFilename
()
const
{
return
filename
;
}
...
...
@@ -81,17 +86,17 @@ void Package::open(const String& n) {
}
}
void
Package
::
save
(
bool
remove
U
nused
)
{
void
Package
::
save
(
bool
remove
_u
nused
)
{
assert
(
!
needSaveAs
());
saveAs
(
filename
,
remove
U
nused
);
saveAs
(
filename
,
remove
_u
nused
);
}
void
Package
::
saveAs
(
const
String
&
name
,
bool
remove
U
nused
)
{
void
Package
::
saveAs
(
const
String
&
name
,
bool
remove
_u
nused
)
{
// type of package
if
(
wxDirExists
(
name
))
{
saveToDirectory
(
name
,
remove
U
nused
);
saveToDirectory
(
name
,
remove
_u
nused
);
}
else
{
saveToZipfile
(
name
,
remove
U
nused
);
saveToZipfile
(
name
,
remove
_u
nused
);
}
filename
=
name
;
// cleanup : remove temp files, remove deleted files from the list
...
...
@@ -101,7 +106,7 @@ void Package::saveAs(const String& name, bool removeUnused) {
// remove corresponding temp file
wxRemoveFile
(
it
->
second
.
tempName
);
}
if
(
!
it
->
second
.
keep
&&
remove
U
nused
)
{
if
(
!
it
->
second
.
keep
&&
remove
_u
nused
)
{
// also remove the record of deleted files
FileInfos
::
iterator
toRemove
=
it
;
++
it
;
...
...
@@ -294,6 +299,9 @@ void Package::openSubdir(const String& name) {
}
// find subdirs
for
(
bool
ok
=
d
.
GetFirst
(
&
f
,
wxEmptyString
,
wxDIR_DIRS
|
wxDIR_HIDDEN
)
;
ok
;
ok
=
d
.
GetNext
(
&
f
))
{
if
(
f
.
empty
()
||
f
.
GetChar
(
0
)
==
_
(
'.'
))
{
return
;
// skip directories starting with '.', like ., .. and .svn
}
openSubdir
(
name
+
f
+
_
(
"/"
));
}
}
...
...
@@ -318,10 +326,10 @@ void Package::openZipfile() {
}
void
Package
::
saveToDirectory
(
const
String
&
saveAs
,
bool
remove
U
nused
)
{
void
Package
::
saveToDirectory
(
const
String
&
saveAs
,
bool
remove
_u
nused
)
{
// write to a directory
FOR_EACH
(
f
,
files
)
{
if
(
!
f
.
second
.
keep
&&
remove
U
nused
)
{
if
(
!
f
.
second
.
keep
&&
remove
_u
nused
)
{
// remove files that are not to be kept
// ignore failure (new file that is not kept)
wxRemoveFile
(
saveAs
+
_
(
"/"
)
+
f
.
first
);
...
...
@@ -342,7 +350,7 @@ void Package::saveToDirectory(const String& saveAs, bool removeUnused) {
}
}
void
Package
::
saveToZipfile
(
const
String
&
saveAs
,
bool
remove
U
nused
)
{
void
Package
::
saveToZipfile
(
const
String
&
saveAs
,
bool
remove
_u
nused
)
{
// create a temporary zip file name
String
tempFile
=
saveAs
+
_
(
".tmp"
);
wxRemoveFile
(
tempFile
);
...
...
@@ -355,7 +363,7 @@ void Package::saveToZipfile(const String& saveAs, bool removeUnused) {
// copy everything to a new zip file, unless it's updated or removed
if
(
zipStream
)
newZip
->
CopyArchiveMetaData
(
*
zipStream
);
FOR_EACH
(
f
,
files
)
{
if
(
!
f
.
second
.
keep
&&
remove
U
nused
)
{
if
(
!
f
.
second
.
keep
&&
remove
_u
nused
)
{
// to remove a file simply don't copy it
}
else
if
(
f
.
second
.
zipEntry
&&
!
f
.
second
.
wasWritten
())
{
// old file, was also in zip, not changed
...
...
@@ -474,11 +482,11 @@ void Packaged::save() {
referenceFile
(
typeName
());
Package
::
save
();
}
void
Packaged
::
saveAs
(
const
String
&
package
)
{
void
Packaged
::
saveAs
(
const
String
&
package
,
bool
remove_unused
)
{
WITH_DYNAMIC_ARG
(
writing_package
,
this
);
writeFile
(
typeName
(),
*
this
);
referenceFile
(
typeName
());
Package
::
saveAs
(
package
);
Package
::
saveAs
(
package
,
remove_unused
);
}
void
Packaged
::
validate
(
Version
)
{
...
...
src/util/io/package.hpp
View file @
5e583dd3
...
...
@@ -60,6 +60,8 @@ class Package : public IntrusivePtrVirtualBase {
bool
needSaveAs
()
const
;
/// Determines the short name of this package: the filename without path or extension
String
name
()
const
;
/// Return the relative filename of this file, the name and extension
String
relativeFilename
()
const
;
/// Return the absolute filename of this file
const
String
&
absoluteFilename
()
const
;
/// The time this package was last modified
...
...
@@ -71,14 +73,14 @@ class Package : public IntrusivePtrVirtualBase {
/// Saves the package, by default saves as a zip file, unless
/// it was already a directory
/** If remove
U
nused=true all files that were in the file and
/** If remove
_u
nused=true all files that were in the file and
* are not touched with referenceFile will be deleted from the new archive!
* This is a form of garbage collection, to get rid of old picture files for example.
*/
void
save
(
bool
remove
U
nused
=
true
);
void
save
(
bool
remove
_u
nused
=
true
);
/// Saves the package under a different filename
void
saveAs
(
const
String
&
package
,
bool
remove
U
nused
=
true
);
void
saveAs
(
const
String
&
package
,
bool
remove
_u
nused
=
true
);
// --------------------------------------------------- : Managing the inside of the package
...
...
@@ -157,6 +159,7 @@ class Package : public IntrusivePtrVirtualBase {
/// Information on files in the package
/** Note: must be public for DECLARE_TYPEOF to work */
typedef
map
<
String
,
FileInfo
>
FileInfos
;
inline
const
FileInfos
&
getFileInfos
()
const
{
return
files
;
}
private:
/// All files in the package
FileInfos
files
;
...
...
@@ -210,7 +213,7 @@ class Packaged : public Package {
/// Ensure the package is fully loaded.
void
loadFully
();
void
save
();
void
saveAs
(
const
String
&
package
);
void
saveAs
(
const
String
&
package
,
bool
remove_unused
=
true
);
protected:
/// filename of the data file, and extension of the package file
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment