Massive re-organization.

This commit is contained in:
Andrew
2013-02-26 16:47:39 -06:00
parent bd64cda672
commit 36396f7c6a
53 changed files with 223 additions and 185 deletions

View File

@ -1,4 +1,4 @@
project(libmmcutil)
project(libUtil)
######## Set compiler flags ########
IF(APPLE)
@ -32,8 +32,6 @@ include/osutils.h
include/userutils.h
include/cmdutils.h
include/inifile.h
include/siglist.h
include/siglist_impl.h
)
@ -43,15 +41,13 @@ src/pathutils.cpp
src/osutils.cpp
src/userutils.cpp
src/cmdutils.cpp
src/inifile.cpp
)
# Set the include dir path.
SET(LIBMMCUTIL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE)
SET(LIBUTIL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE)
add_definitions(-DLIBMMCUTIL_LIBRARY)
add_definitions(-DLIBUTIL_LIBRARY)
add_library(libmmcutil SHARED ${LIBUTIL_SOURCES} ${LIBUTIL_HEADERS})
qt5_use_modules(libmmcutil Core)
target_link_libraries(libmmcutil)
add_library(libUtil SHARED ${LIBUTIL_SOURCES} ${LIBUTIL_HEADERS})
qt5_use_modules(libUtil Core)
target_link_libraries(libUtil)

View File

@ -42,7 +42,7 @@ namespace Commandline {
namespace FlagStyle
{
enum LIBMMCUTIL_EXPORT Enum
enum LIBUTIL_EXPORT Enum
{
GNU, /**< --option and -o (GNU Style) */
Unix, /**< -option and -o (Unix Style) */
@ -60,7 +60,7 @@ enum LIBMMCUTIL_EXPORT Enum
*/
namespace ArgumentStyle
{
enum LIBMMCUTIL_EXPORT Enum
enum LIBUTIL_EXPORT Enum
{
Space, /**< --option=value */
Equals, /**< --option value */
@ -75,7 +75,7 @@ enum LIBMMCUTIL_EXPORT Enum
namespace OptionType
{
enum LIBMMCUTIL_EXPORT Enum
enum LIBUTIL_EXPORT Enum
{
Switch,
Option
@ -85,7 +85,7 @@ enum LIBMMCUTIL_EXPORT Enum
/**
* @brief The ParsingError class
*/
class LIBMMCUTIL_EXPORT ParsingError : public std::exception
class LIBUTIL_EXPORT ParsingError : public std::exception
{
public:
ParsingError(const QString &what);
@ -100,7 +100,7 @@ private:
/**
* @brief The Parser class
*/
class LIBMMCUTIL_EXPORT Parser
class LIBUTIL_EXPORT Parser
{
public:
/**

View File

@ -1,38 +0,0 @@
/* Copyright 2013 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef INIFILE_H
#define INIFILE_H
#include <QMap>
#include <QString>
#include <QVariant>
#include "libutil_config.h"
// Sectionless INI parser (for instance config files)
class LIBMMCUTIL_EXPORT INIFile : public QMap<QString, QVariant>
{
public:
explicit INIFile();
bool loadFile(QString fileName);
bool saveFile(QString fileName);
QVariant get(QString key, QVariant def) const;
void set(QString key, QVariant val);
};
#endif // INIFILE_H

View File

@ -18,10 +18,10 @@
#include <QtCore/QtGlobal>
#ifdef LIBMMCUTIL_LIBRARY
# define LIBMMCUTIL_EXPORT Q_DECL_EXPORT
#ifdef LIBUTIL_LIBRARY
# define LIBUTIL_EXPORT Q_DECL_EXPORT
#else
# define LIBMMCUTIL_EXPORT Q_DECL_IMPORT
# define LIBUTIL_EXPORT Q_DECL_IMPORT
#endif
#endif // LIBUTIL_CONFIG_H

View File

@ -20,9 +20,9 @@
#include "libutil_config.h"
LIBMMCUTIL_EXPORT QString PathCombine(QString path1, QString path2);
LIBMMCUTIL_EXPORT QString PathCombine(QString path1, QString path2, QString path3);
LIBUTIL_EXPORT QString PathCombine(QString path1, QString path2);
LIBUTIL_EXPORT QString PathCombine(QString path1, QString path2, QString path3);
LIBMMCUTIL_EXPORT QString AbsolutePath(QString path);
LIBUTIL_EXPORT QString AbsolutePath(QString path);
#endif // PATHUTILS_H

View File

@ -8,12 +8,12 @@
namespace Util
{
// Get the Directory representing the User's Desktop
LIBMMCUTIL_EXPORT QString getDesktopDir();
LIBUTIL_EXPORT QString getDesktopDir();
// Create a shortcut at *location*, pointing to *dest* called with the arguments *args*
// call it *name* and assign it the icon *icon*
// return true if operation succeeded
LIBMMCUTIL_EXPORT bool createShortCut(QString location, QString dest, QStringList args, QString name, QString iconLocation);
LIBUTIL_EXPORT bool createShortCut(QString location, QString dest, QStringList args, QString name, QString iconLocation);
}
#endif // USERUTILS_H

View File

@ -1,86 +0,0 @@
/* Copyright 2013 MultiMC Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "include/inifile.h"
#include <QFile>
#include <QTextStream>
#include <QStringList>
INIFile::INIFile()
{
}
bool INIFile::saveFile(QString fileName)
{
// TODO Handle errors.
QFile file(fileName);
file.open(QIODevice::WriteOnly);
QTextStream out(&file);
for (Iterator iter = begin(); iter != end(); iter++)
{
out << iter.key() << "=" << iter.value().toString() << "\n";
}
return true;
}
bool INIFile::loadFile(QString fileName)
{
// TODO Handle errors.
QFile file(fileName);
file.open(QIODevice::ReadOnly);
QTextStream in(&file);
QStringList lines = in.readAll().split('\n');
for (int i = 0; i < lines.count(); i++)
{
QString & lineRaw = lines[i];
// Ignore comments.
QString line = lineRaw.left(lineRaw.indexOf('#')).trimmed();
int eqPos = line.indexOf('=');
if(eqPos == -1)
continue;
QString key = line.left(eqPos).trimmed();
QString valueStr = line.right(line.length() - eqPos - 1).trimmed();
QVariant value(valueStr);
/*
QString dbg = key;
dbg += " = ";
dbg += valueStr;
qDebug(dbg.toLocal8Bit());
*/
this->operator [](key) = value;
}
return true;
}
QVariant INIFile::get(QString key, QVariant def) const
{
if (!this->contains(key))
return def;
else
return this->operator [](key);
}
void INIFile::set(QString key, QVariant val)
{
this->operator [](key) = val;
}