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
f3924ec8
Commit
f3924ec8
authored
Oct 07, 2006
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Package manager for maanging the data files
parent
54916c4a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
1 deletion
+98
-1
src/util/io/package.hpp
src/util/io/package.hpp
+1
-1
src/util/io/package_manager.cpp
src/util/io/package_manager.cpp
+37
-0
src/util/io/package_manager.hpp
src/util/io/package_manager.hpp
+60
-0
No files found.
src/util/io/package.hpp
View file @
f3924ec8
...
@@ -172,7 +172,7 @@ class Packaged : public Package {
...
@@ -172,7 +172,7 @@ class Packaged : public Package {
protected:
protected:
/// filename of the data file, and extension of the package file
/// filename of the data file, and extension of the package file
virtual
String
typeName
()
=
0
;
virtual
String
typeName
()
const
=
0
;
/// Can be overloaded to do validation after loading
/// Can be overloaded to do validation after loading
virtual
void
validate
()
{}
virtual
void
validate
()
{}
...
...
src/util/io/package_manager.cpp
0 → 100644
View file @
f3924ec8
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <util/io/package_manager.hpp>
#include <util/error.hpp>
// ----------------------------------------------------------------------------- : PackageManager
String
programDir
()
{
return
_
(
"."
);
//TODO
}
PackageManager
packages
;
PackageManager
::
PackageManager
()
{
// determine data directory
dataDirectory
=
programDir
();
// check if this is the actual data directory, especially during debugging,
// the data may be higher up:
// exe path = mse/build/debug/mse.exe
// data path = mse/data
while
(
!
wxDirExists
(
dataDirectory
+
_
(
"/data"
)))
{
String
d
=
dataDirectory
;
dataDirectory
=
wxPathOnly
(
dataDirectory
);
if
(
d
==
dataDirectory
)
{
// we are at the root -> 'data' not found anywhere in the path -> fatal error
throw
Error
(
_
(
"The MSE data files can not be found, there should be a directory called 'data' with these files"
));
}
}
dataDirectory
+=
_
(
"/data"
);
}
src/util/io/package_manager.hpp
0 → 100644
View file @
f3924ec8
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_UTIL_IO_PACKAGE_MANAGER
#define HEADER_UTIL_IO_PACKAGE_MANAGER
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/io/package.hpp>
#include <wx/filename.h>
DECLARE_POINTER_TYPE
(
Packaged
);
// ----------------------------------------------------------------------------- : PackageManager
/// Package manager, loads data files from the default data directory
/** The PackageManager ensures that each package is only loaded once.
* There is a single global instance of the PackageManager, called packages
*/
class
PackageManager
{
public:
PackageManager
();
/// Open a package with the specified name (including extension)
template
<
typename
T
>
shared_ptr
<
T
>
open
(
const
String
&
name
)
{
wxFileName
fn
(
dataDirectory
+
_
(
"/"
)
+
name
);
fn
.
Normalize
();
String
filename
=
fn
.
GetFullPath
();
// Is this package already loaded?
PackagedP
&
p
=
loadedPackages
[
filename
];
shared_ptr
<
T
>
typedP
=
dynamic_pointer_cast
<
T
>
(
p
);
if
(
typedP
)
{
return
typedP
;
}
else
{
// not loaded, or loaded with wrong type
p
=
typedP
=
new_shared
<
T
>
();
typedP
->
open
(
filename
);
return
typedP
;
}
}
/// Open a package with the specified name
/// the type of package is determined by its extension!
PackagedP
openAnyPackage
(
const
String
&
filename
);
private:
map
<
String
,
PackagedP
>
loadedPackages
;
String
dataDirectory
;
};
/// The global PackageManager instance
extern
PackageManager
packages
;
// ----------------------------------------------------------------------------- : EOF
#endif
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