refactor indendation, fix a bug in MinecraftProcess & fix a bug in

InstanceLauncher
This commit is contained in:
Orochimarufan 2013-02-25 22:47:03 +01:00
parent f01bf10dc5
commit f4c9cb8c1d
13 changed files with 206 additions and 210 deletions

View File

@ -85,7 +85,7 @@ protected:
QStringList m_arguments; QStringList m_arguments;
void genArgs(); void genArgs();
void log(QString text); void log(QString text, ConsoleWindow::WriteMode mode = ConsoleWindow::MULTIMC);
protected slots: protected slots:
void finish(int, QProcess::ExitStatus status); void finish(int, QProcess::ExitStatus status);

View File

@ -197,6 +197,8 @@ void MinecraftProcess::launch()
start(m_instance->settings().get("JavaPath").toString(), m_arguments); start(m_instance->settings().get("JavaPath").toString(), m_arguments);
if (!waitForStarted()) if (!waitForStarted())
{ {
log("Could not launch minecraft!", ConsoleWindow::ERROR);
return;
//TODO: error handling //TODO: error handling
} }

View File

@ -70,7 +70,7 @@ QString StubKeyring::getPassword(QString service, QString username)
return unscramble64(m_settings.value(key).toString()); return unscramble64(m_settings.value(key).toString());
} }
inline bool StubKeyring::hasPassword(QString service, QString username) bool StubKeyring::hasPassword(QString service, QString username)
{ {
return m_settings.contains(generateKey(service, username)); return m_settings.contains(generateKey(service, username));
} }

View File

@ -73,15 +73,6 @@ enum LIBUTIL_EXPORT Enum
}; };
} }
namespace OptionType
{
enum LIBUTIL_EXPORT Enum
{
Switch,
Option
};
}
/** /**
* @brief The ParsingError class * @brief The ParsingError class
*/ */
@ -211,6 +202,12 @@ private:
FlagStyle::Enum m_flagStyle; FlagStyle::Enum m_flagStyle;
ArgumentStyle::Enum m_argStyle; ArgumentStyle::Enum m_argStyle;
enum OptionType
{
otSwitch,
otOption
};
// Important: the common part MUST BE COMMON ON ALL THREE structs // Important: the common part MUST BE COMMON ON ALL THREE structs
struct CommonDef { struct CommonDef {
QString name; QString name;
@ -226,7 +223,7 @@ private:
QString metavar; QString metavar;
QVariant def; QVariant def;
// option // option
OptionType::Enum type; OptionType type;
QChar flag; QChar flag;
}; };

View File

@ -56,7 +56,7 @@ void Parser::addSwitch(QString name, bool def)
throw "Name not unique"; throw "Name not unique";
OptionDef *param = new OptionDef; OptionDef *param = new OptionDef;
param->type = OptionType::Switch; param->type = otSwitch;
param->name = name; param->name = name;
param->metavar = QString("<%1>").arg(name); param->metavar = QString("<%1>").arg(name);
param->def = def; param->def = def;
@ -72,7 +72,7 @@ void Parser::addOption(QString name, QVariant def)
throw "Name not unique"; throw "Name not unique";
OptionDef *param = new OptionDef; OptionDef *param = new OptionDef;
param->type = OptionType::Option; param->type = otOption;
param->name = name; param->name = name;
param->metavar = QString("<%1>").arg(name); param->metavar = QString("<%1>").arg(name);
param->def = def; param->def = def;
@ -161,7 +161,7 @@ QString Parser::compileHelp(QString progName, int helpIndent, bool useFlags)
help << flagPrefix << option->flag << ", "; help << flagPrefix << option->flag << ", ";
} }
help << optPrefix << option->name; help << optPrefix << option->name;
if (option->type == OptionType::Option) if (option->type == otOption)
{ {
QString arg = QString("%1%2").arg(((m_argStyle == ArgumentStyle::Equals) ? "=" : " "), option->metavar); QString arg = QString("%1%2").arg(((m_argStyle == ArgumentStyle::Equals) ? "=" : " "), option->metavar);
nameLength += arg.length(); nameLength += arg.length();
@ -193,7 +193,7 @@ QString Parser::compileUsage(QString progName, bool useFlags)
usage << flagPrefix << option->flag; usage << flagPrefix << option->flag;
else else
usage << optPrefix << option->name; usage << optPrefix << option->name;
if (option->type == OptionType::Option) if (option->type == otOption)
usage << ((m_argStyle == ArgumentStyle::Equals) ? "=" : " ") << option->metavar; usage << ((m_argStyle == ArgumentStyle::Equals) ? "=" : " ") << option->metavar;
usage << "]"; usage << "]";
} }
@ -265,9 +265,9 @@ QHash<QString, QVariant> Parser::parse(QStringList argv)
throw ParsingError(QString("Option %2%1 was given multiple times").arg(name, optionPrefix)); throw ParsingError(QString("Option %2%1 was given multiple times").arg(name, optionPrefix));
OptionDef *option = m_options[name]; OptionDef *option = m_options[name];
if (option->type == OptionType::Switch) if (option->type == otSwitch)
map[name] = true; map[name] = true;
else //if (option->type == OptionType::Option) else //if (option->type == otOption)
{ {
if (m_argStyle == ArgumentStyle::Space) if (m_argStyle == ArgumentStyle::Space)
expecting.append(name); expecting.append(name);
@ -312,9 +312,9 @@ QHash<QString, QVariant> Parser::parse(QStringList argv)
if (map.contains(option->name)) if (map.contains(option->name))
throw ParsingError(QString("Option %2%1 was given multiple times").arg(option->name, optionPrefix)); throw ParsingError(QString("Option %2%1 was given multiple times").arg(option->name, optionPrefix));
if (option->type == OptionType::Switch) if (option->type == otSwitch)
map[option->name] = true; map[option->name] = true;
else //if (option->type == OptionType::Option) else //if (option->type == otOption)
{ {
if (m_argStyle == ArgumentStyle::Space) if (m_argStyle == ArgumentStyle::Space)
expecting.append(option->name); expecting.append(option->name);

View File

@ -66,12 +66,9 @@ private:
{ {
inst = iter.next(); inst = iter.next();
if (inst->id() == instId) if (inst->id() == instId)
break; return inst;
} }
if (inst->id() != instId)
return InstancePtr(); return InstancePtr();
else
return iter.peekPrevious();
} }
private slots: private slots: