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
4c527278
Commit
4c527278
authored
Aug 09, 2008
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow writing files anywhere from the command lines interface, not just in the working directory
parent
4f13ac9f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
26 deletions
+69
-26
src/cli/cli_main.cpp
src/cli/cli_main.cpp
+19
-3
src/data/export_template.cpp
src/data/export_template.cpp
+3
-0
src/data/export_template.hpp
src/data/export_template.hpp
+3
-0
src/script/functions/export.cpp
src/script/functions/export.cpp
+44
-23
No files found.
src/cli/cli_main.cpp
View file @
4c527278
...
...
@@ -26,6 +26,7 @@ CLISetInterface::CLISetInterface(const SetP& set, bool quiet)
throw
Error
(
_
(
"Can not run command line interface without a console;
\n
start MSE with
\"
mse.com --cli
\"
"
));
}
ei
.
directory_relative
=
ei
.
directory_absolute
=
wxGetCwd
();
ei
.
allow_writes_outside
=
true
;
setSet
(
set
);
run
();
}
...
...
@@ -100,6 +101,8 @@ void CLISetInterface::showUsage() {
cli
<<
_
(
" :load <setfile> Load a different set file.
\n
"
);
cli
<<
_
(
" :quit Exit the MSE command line interface.
\n
"
);
cli
<<
_
(
" :reset Clear all local variable definitions.
\n
"
);
cli
<<
_
(
" :pwd Print the current working directory.
\n
"
);
cli
<<
_
(
" :cd Change working directory.
\n
"
);
cli
<<
_
(
" :! <command> Perform a shell command.
\n
"
);
cli
<<
_
(
"
\n
Commands can be abreviated to their first letter if there is no ambiguity.
\n\n
"
);
}
...
...
@@ -122,17 +125,30 @@ void CLISetInterface::handleCommand(const String& command) {
showUsage
();
}
else
if
(
before
==
_
(
":l"
)
||
before
==
_
(
":load"
))
{
if
(
arg
.
empty
())
{
cli
<<
_
(
"Give a filename to open.
\n
"
);
cli
.
showError
(
_
(
"Give a filename to open."
)
);
}
else
{
setSet
(
import_set
(
arg
));
}
}
else
if
(
before
==
_
(
":r"
)
||
before
==
_
(
":reset"
))
{
Context
&
ctx
=
getContext
();
ei
.
exported_images
.
clear
();
ctx
.
closeScope
(
scope
);
scope
=
ctx
.
openScope
();
}
else
if
(
before
==
_
(
":c"
)
||
before
==
_
(
":cd"
))
{
if
(
arg
.
empty
())
{
cli
.
showError
(
_
(
"Give a new working directory."
));
}
else
{
if
(
!
wxSetWorkingDirectory
(
arg
))
{
cli
.
showError
(
_
(
"Can't change working directory to "
)
+
arg
);
}
else
{
ei
.
directory_relative
=
ei
.
directory_absolute
=
wxGetCwd
();
}
}
}
else
if
(
before
==
_
(
":pwd"
)
||
before
==
_
(
":p"
))
{
cli
<<
ei
.
directory_absolute
<<
ENDL
;
}
else
if
(
before
==
_
(
":!"
))
{
if
(
arg
.
empty
())
{
cli
<<
_
(
"Give a shell command to execute.
\n
"
);
cli
.
showError
(
_
(
"Give a shell command to execute."
)
);
}
else
{
#ifdef __WXMSW__
_wsystem
(
arg
.
c_str
());
...
...
@@ -144,7 +160,7 @@ void CLISetInterface::handleCommand(const String& command) {
#endif
}
}
else
{
cli
<<
_
(
"Unknown command, type :help for help.
\n
"
);
cli
.
showError
(
_
(
"Unknown command, type :help for help."
)
);
}
}
else
if
(
command
==
_
(
"exit"
)
||
command
==
_
(
"quit"
))
{
cli
<<
_
(
"Use :quit to quit
\n
"
);
...
...
src/data/export_template.cpp
View file @
4c527278
...
...
@@ -9,6 +9,7 @@
#include <util/prec.hpp>
#include <data/export_template.hpp>
#include <data/game.hpp>
#include <data/set.hpp>
#include <data/field.hpp>
// ----------------------------------------------------------------------------- : Export template, basics
...
...
@@ -45,3 +46,5 @@ IMPLEMENT_REFLECTION(ExportTemplate) {
// ----------------------------------------------------------------------------- : ExportInfo
IMPLEMENT_DYNAMIC_ARG
(
ExportInfo
*
,
export_info
,
nullptr
);
ExportInfo
::
ExportInfo
()
:
allow_writes_outside
(
false
)
{}
src/data/export_template.hpp
View file @
4c527278
...
...
@@ -45,12 +45,15 @@ class ExportTemplate : public Packaged {
/// Information that can be used by export functions
struct
ExportInfo
{
ExportInfo
();
SetP
set
;
///< The set that is being exported
ExportTemplateP
export_template
;
///< The export template used
String
directory_relative
;
///< The directory for storing extra files (or "" if !export->create_directory)
/// This is just the directory name
String
directory_absolute
;
///< The absolute path of the directory
map
<
String
,
wxSize
>
exported_images
;
///< Images (from symbol font) already exported, and their size
bool
allow_writes_outside
;
///< Can files outside the directory be written to?
};
DECLARE_DYNAMIC_ARG
(
ExportInfo
*
,
export_info
);
...
...
src/script/functions/export.cpp
View file @
4c527278
...
...
@@ -34,6 +34,29 @@ void guard_export_info(const String& fun, bool need_template = false) {
}
}
/// Find an absolute filename for a relative filename from an export template,
/// Returns the absolute filename, and may modify the relative name.
String
get_export_full_path
(
String
&
rel_name
)
{
ExportInfo
&
ei
=
*
export_info
();
// the absolute path
wxFileName
fn
(
rel_name
);
fn
.
Normalize
(
wxPATH_NORM_ALL
,
ei
.
directory_absolute
);
if
(
!
ei
.
allow_writes_outside
)
{
// check if path is okay
wxFileName
fn2
(
_
(
"x"
));
fn2
.
SetPath
(
ei
.
directory_absolute
);
fn2
.
Normalize
(
wxPATH_NORM_ALL
,
ei
.
directory_absolute
);
String
p1
=
fn
.
GetFullPath
();
String
p2
=
fn2
.
GetFullPath
();
p2
.
resize
(
p2
.
size
()
-
1
);
// drop the x
if
(
p2
.
empty
()
||
p1
.
size
()
<
p2
.
size
()
||
p1
.
substr
(
0
,
p2
.
size
()
-
1
)
!=
p2
.
substr
(
0
,
p2
.
size
()
-
1
))
{
throw
ScriptError
(
_
(
"Not a relative filename: "
)
+
rel_name
);
}
}
rel_name
=
fn
.
GetFullName
();
return
fn
.
GetFullPath
();
}
// ----------------------------------------------------------------------------- : HTML
// An HTML tag
...
...
@@ -351,15 +374,16 @@ SCRIPT_FUNCTION(to_text) {
SCRIPT_FUNCTION
(
copy_file
)
{
guard_export_info
(
_
(
"copy_file"
));
SCRIPT_PARAM_C
(
String
,
input
);
// file to copy
ExportInfo
&
ei
=
*
export_info
();
wxFileName
fn
(
input
)
;
fn
.
SetPath
(
ei
.
directory_absolut
e
);
// output path
String
out_name
=
input
;
String
out_path
=
get_export_full_path
(
out_nam
e
);
// copy
ExportInfo
&
ei
=
*
export_info
();
InputStreamP
in
=
ei
.
export_template
->
openIn
(
input
);
wxFileOutputStream
out
(
fn
.
GetFullPath
()
);
if
(
!
out
.
Ok
())
throw
Error
(
_
(
"Unable to open file '"
)
+
fn
.
GetFullPath
()
+
_
(
"' for output"
));
wxFileOutputStream
out
(
out_path
);
if
(
!
out
.
Ok
())
throw
Error
(
_
(
"Unable to open file '"
)
+
out_path
+
_
(
"' for output"
));
out
.
Write
(
*
in
);
SCRIPT_RETURN
(
fn
.
GetFullName
()
);
SCRIPT_RETURN
(
out_name
);
}
// write a file to the destination directory
...
...
@@ -367,29 +391,26 @@ SCRIPT_FUNCTION(write_text_file) {
guard_export_info
(
_
(
"write_text_file"
));
SCRIPT_PARAM_C
(
String
,
input
);
// text to write
SCRIPT_PARAM
(
String
,
file
);
// file to write to
// filename
wxFileName
fn
;
fn
.
SetPath
(
export_info
()
->
directory_absolute
);
fn
.
SetFullName
(
file
);
// output path
String
out_path
=
get_export_full_path
(
file
);
// write
wxFileOutputStream
out
(
fn
.
GetFullPath
()
);
if
(
!
out
.
Ok
())
throw
Error
(
_
(
"Unable to open file '"
)
+
fn
.
GetFullPath
()
+
_
(
"' for output"
));
wxFileOutputStream
out
(
out_path
);
if
(
!
out
.
Ok
())
throw
Error
(
_
(
"Unable to open file '"
)
+
out_path
+
_
(
"' for output"
));
wxTextOutputStream
tout
(
out
);
tout
.
WriteString
(
BYTE_ORDER_MARK
);
tout
.
WriteString
(
input
);
SCRIPT_RETURN
(
f
n
.
GetFullName
()
);
SCRIPT_RETURN
(
f
ile
);
}
SCRIPT_FUNCTION
(
write_image_file
)
{
guard_export_info
(
_
(
"write_image_file"
));
ExportInfo
&
ei
=
*
export_info
();
// filename
// output path
SCRIPT_PARAM
(
String
,
file
);
// file to write to
wxFileName
fn
;
fn
.
SetPath
(
ei
.
directory_absolute
);
fn
.
SetFullName
(
file
);
if
(
ei
.
exported_images
.
find
(
f
n
.
GetFullName
()
)
!=
ei
.
exported_images
.
end
())
{
SCRIPT_RETURN
(
f
n
.
GetFullName
()
);
// already written an image with this name
String
out_path
=
get_export_full_path
(
file
)
;
// duplicates?
ExportInfo
&
ei
=
*
export_info
(
);
if
(
ei
.
exported_images
.
find
(
f
ile
)
!=
ei
.
exported_images
.
end
())
{
SCRIPT_RETURN
(
f
ile
);
// already written an image with this name
}
// get image
SCRIPT_PARAM_C
(
ScriptValueP
,
input
);
...
...
@@ -405,9 +426,9 @@ SCRIPT_FUNCTION(write_image_file) {
}
if
(
!
image
.
Ok
())
throw
Error
(
_
(
"Unable to generate image for file "
)
+
file
);
// write
image
.
SaveFile
(
fn
.
GetFullPath
()
);
ei
.
exported_images
.
insert
(
make_pair
(
f
n
.
GetFullName
()
,
wxSize
(
image
.
GetWidth
(),
image
.
GetHeight
())));
SCRIPT_RETURN
(
f
n
.
GetFullName
()
);
image
.
SaveFile
(
out_path
);
ei
.
exported_images
.
insert
(
make_pair
(
f
ile
,
wxSize
(
image
.
GetWidth
(),
image
.
GetHeight
())));
SCRIPT_RETURN
(
f
ile
);
}
// ----------------------------------------------------------------------------- : Init
...
...
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