diff options
author | Petr Mrázek <peterix@gmail.com> | 2015-10-05 01:47:27 +0200 |
---|---|---|
committer | Petr Mrázek <peterix@gmail.com> | 2015-10-05 01:47:27 +0200 |
commit | f93f867c3da084c6d6c5e3ed23896609cff0e692 (patch) | |
tree | 3234c54d9aefb5566afc0c8ff52874e20ab35304 /depends/util/include | |
parent | 7459eb627c97d27ef6e12cdededa48e1ff03d533 (diff) | |
download | MultiMC-f93f867c3da084c6d6c5e3ed23896609cff0e692.tar MultiMC-f93f867c3da084c6d6c5e3ed23896609cff0e692.tar.gz MultiMC-f93f867c3da084c6d6c5e3ed23896609cff0e692.tar.lz MultiMC-f93f867c3da084c6d6c5e3ed23896609cff0e692.tar.xz MultiMC-f93f867c3da084c6d6c5e3ed23896609cff0e692.zip |
NOISSUE dissolve util library
Diffstat (limited to 'depends/util/include')
-rw-r--r-- | depends/util/include/cmdutils.h | 255 | ||||
-rw-r--r-- | depends/util/include/modutils.h | 113 | ||||
-rw-r--r-- | depends/util/include/osutils.h | 26 | ||||
-rw-r--r-- | depends/util/include/pathutils.h | 83 | ||||
-rw-r--r-- | depends/util/include/userutils.h | 17 |
5 files changed, 0 insertions, 494 deletions
diff --git a/depends/util/include/cmdutils.h b/depends/util/include/cmdutils.h deleted file mode 100644 index 8bf39eaa..00000000 --- a/depends/util/include/cmdutils.h +++ /dev/null @@ -1,255 +0,0 @@ -/* Copyright 2013-2015 MultiMC Contributors - * - * Authors: Orochimarufan <orochimarufan.x3@gmail.com> - * - * 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. - */ - -#pragma once - -#include <exception> -#include <stdexcept> - -#include <QString> -#include <QVariant> -#include <QHash> -#include <QStringList> - -#include "multimc_util_export.h" - -/** - * @file libutil/include/cmdutils.h - * @brief commandline parsing and processing utilities - */ - -namespace Util -{ -namespace Commandline -{ - -/** - * @brief split a string into argv items like a shell would do - * @param args the argument string - * @return a QStringList containing all arguments - */ -MULTIMC_UTIL_EXPORT QStringList splitArgs(QString args); - -/** - * @brief The FlagStyle enum - * Specifies how flags are decorated - */ - -namespace FlagStyle -{ -enum Enum -{ - GNU, /**< --option and -o (GNU Style) */ - Unix, /**< -option and -o (Unix Style) */ - Windows, /**< /option and /o (Windows Style) */ -#ifdef Q_OS_WIN32 - Default = Windows -#else - Default = GNU -#endif -}; -} - -/** - * @brief The ArgumentStyle enum - */ -namespace ArgumentStyle -{ -enum Enum -{ - Space, /**< --option=value */ - Equals, /**< --option value */ - SpaceAndEquals, /**< --option[= ]value */ -#ifdef Q_OS_WIN32 - Default = Equals -#else - Default = SpaceAndEquals -#endif -}; -} - -/** - * @brief The ParsingError class - */ -class MULTIMC_UTIL_EXPORT ParsingError : public std::runtime_error -{ -public: - ParsingError(const QString &what); -}; - -/** - * @brief The Parser class - */ -class MULTIMC_UTIL_EXPORT Parser -{ -public: - /** - * @brief Parser constructor - * @param flagStyle the FlagStyle to use in this Parser - * @param argStyle the ArgumentStyle to use in this Parser - */ - Parser(FlagStyle::Enum flagStyle = FlagStyle::Default, - ArgumentStyle::Enum argStyle = ArgumentStyle::Default); - - /** - * @brief set the flag style - * @param style - */ - void setFlagStyle(FlagStyle::Enum style); - - /** - * @brief get the flag style - * @return - */ - FlagStyle::Enum flagStyle(); - - /** - * @brief set the argument style - * @param style - */ - void setArgumentStyle(ArgumentStyle::Enum style); - - /** - * @brief get the argument style - * @return - */ - ArgumentStyle::Enum argumentStyle(); - - /** - * @brief define a boolean switch - * @param name the parameter name - * @param def the default value - */ - void addSwitch(QString name, bool def = false); - - /** - * @brief define an option that takes an additional argument - * @param name the parameter name - * @param def the default value - */ - void addOption(QString name, QVariant def = QVariant()); - - /** - * @brief define a positional argument - * @param name the parameter name - * @param required wether this argument is required - * @param def the default value - */ - void addArgument(QString name, bool required = true, QVariant def = QVariant()); - - /** - * @brief adds a flag to an existing parameter - * @param name the (existing) parameter name - * @param flag the flag character - * @see addSwitch addArgument addOption - * Note: any one parameter can only have one flag - */ - void addShortOpt(QString name, QChar flag); - - /** - * @brief adds documentation to a Parameter - * @param name the parameter name - * @param metavar a string to be displayed as placeholder for the value - * @param doc a QString containing the documentation - * Note: on positional arguments, metavar replaces the name as displayed. - * on options , metavar replaces the value placeholder - */ - void addDocumentation(QString name, QString doc, QString metavar = QString()); - - /** - * @brief generate a help message - * @param progName the program name to use in the help message - * @param helpIndent how much the parameter documentation should be indented - * @param flagsInUsage whether we should use flags instead of options in the usage - * @return a help message - */ - QString compileHelp(QString progName, int helpIndent = 22, bool flagsInUsage = true); - - /** - * @brief generate a short usage message - * @param progName the program name to use in the usage message - * @param useFlags whether we should use flags instead of options - * @return a usage message - */ - QString compileUsage(QString progName, bool useFlags = true); - - /** - * @brief parse - * @param argv a QStringList containing the program ARGV - * @return a QHash mapping argument names to their values - */ - QHash<QString, QVariant> parse(QStringList argv); - - /** - * @brief clear all definitions - */ - void clear(); - - ~Parser(); - -private: - FlagStyle::Enum m_flagStyle; - ArgumentStyle::Enum m_argStyle; - - enum OptionType - { - otSwitch, - otOption - }; - - // Important: the common part MUST BE COMMON ON ALL THREE structs - struct CommonDef - { - QString name; - QString doc; - QString metavar; - QVariant def; - }; - - struct OptionDef - { - // common - QString name; - QString doc; - QString metavar; - QVariant def; - // option - OptionType type; - QChar flag; - }; - - struct PositionalDef - { - // common - QString name; - QString doc; - QString metavar; - QVariant def; - // positional - bool required; - }; - - QHash<QString, OptionDef *> m_options; - QHash<QChar, OptionDef *> m_flags; - QHash<QString, CommonDef *> m_params; - QList<PositionalDef *> m_positionals; - QList<OptionDef *> m_optionList; - - void getPrefix(QString &opt, QString &flag); -}; -} -} diff --git a/depends/util/include/modutils.h b/depends/util/include/modutils.h deleted file mode 100644 index fde51881..00000000 --- a/depends/util/include/modutils.h +++ /dev/null @@ -1,113 +0,0 @@ -#pragma once - -#include <QString> -#include <QList> - -#include "multimc_util_export.h" - -class QUrl; - -namespace Util -{ -struct Version -{ - Version(const QString &str); - Version() {} - - bool operator<(const Version &other) const; - bool operator<=(const Version &other) const; - bool operator>(const Version &other) const; - bool operator>=(const Version &other) const; - bool operator==(const Version &other) const; - bool operator!=(const Version &other) const; - - QString toString() const - { - return m_string; - } - -private: - QString m_string; - struct Section - { - explicit Section(const QString &fullString) - { - m_fullString = fullString; - int cutoff = m_fullString.size(); - for(int i = 0; i < m_fullString.size(); i++) - { - if(!m_fullString[i].isDigit()) - { - cutoff = i; - break; - } - } - auto numPart = m_fullString.leftRef(cutoff); - if(numPart.size()) - { - numValid = true; - m_numPart = numPart.toInt(); - } - auto stringPart = m_fullString.midRef(cutoff); - if(stringPart.size()) - { - m_stringPart = stringPart.toString(); - } - } - explicit Section() {} - bool numValid = false; - int m_numPart = 0; - QString m_stringPart; - QString m_fullString; - - inline bool operator!=(const Section &other) const - { - if(numValid && other.numValid) - { - return m_numPart != other.m_numPart || m_stringPart != other.m_stringPart; - } - else - { - return m_fullString != other.m_fullString; - } - } - inline bool operator<(const Section &other) const - { - if(numValid && other.numValid) - { - if(m_numPart < other.m_numPart) - return true; - if(m_numPart == other.m_numPart && m_stringPart < other.m_stringPart) - return true; - return false; - } - else - { - return m_fullString < other.m_fullString; - } - } - inline bool operator>(const Section &other) const - { - if(numValid && other.numValid) - { - if(m_numPart > other.m_numPart) - return true; - if(m_numPart == other.m_numPart && m_stringPart > other.m_stringPart) - return true; - return false; - } - else - { - return m_fullString > other.m_fullString; - } - } - }; - QList<Section> m_sections; - - void parse(); -}; - -MULTIMC_UTIL_EXPORT bool versionIsInInterval(const QString &version, const QString &interval); -MULTIMC_UTIL_EXPORT bool versionIsInInterval(const Version &version, const QString &interval); -} - diff --git a/depends/util/include/osutils.h b/depends/util/include/osutils.h deleted file mode 100644 index d6875e45..00000000 --- a/depends/util/include/osutils.h +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright 2013-2015 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. - */ - -#pragma once - -#include <QString> - -#if defined _WIN32 | defined _WIN64 -#define WINDOWS 1 -#elif __APPLE__ &__MACH__ -#define OSX 1 -#elif __linux__ -#define LINUX 1 -#endif diff --git a/depends/util/include/pathutils.h b/depends/util/include/pathutils.h deleted file mode 100644 index ff23fa5d..00000000 --- a/depends/util/include/pathutils.h +++ /dev/null @@ -1,83 +0,0 @@ -/* Copyright 2013-2015 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. - */ - -#pragma once - -#include <QString> -#include <QDir> - -#include "multimc_util_export.h" - -MULTIMC_UTIL_EXPORT QString PathCombine(QString path1, QString path2); -MULTIMC_UTIL_EXPORT QString PathCombine(QString path1, QString path2, QString path3); - -MULTIMC_UTIL_EXPORT QString AbsolutePath(QString path); - -/** - * Resolve an executable - * - * Will resolve: - * single executable (by name) - * relative path - * absolute path - * - * @return absolute path to executable or null string - */ -MULTIMC_UTIL_EXPORT QString ResolveExecutable(QString path); - -/** - * Normalize path - * - * Any paths inside the current directory will be normalized to relative paths (to current) - * Other paths will be made absolute - * - * Returns false if the path logic somehow filed (and normalizedPath in invalid) - */ -MULTIMC_UTIL_EXPORT QString NormalizePath(QString path); - -MULTIMC_UTIL_EXPORT QString RemoveInvalidFilenameChars(QString string, QChar replaceWith = '-'); - -MULTIMC_UTIL_EXPORT QString DirNameFromString(QString string, QString inDir = "."); - -/** - * Creates all the folders in a path for the specified path - * last segment of the path is treated as a file name and is ignored! - */ -MULTIMC_UTIL_EXPORT bool ensureFilePathExists(QString filenamepath); - -/** - * Creates all the folders in a path for the specified path - * last segment of the path is treated as a folder name and is created! - */ -MULTIMC_UTIL_EXPORT bool ensureFolderPathExists(QString filenamepath); - -/** - * Copy a folder recursively - */ -MULTIMC_UTIL_EXPORT bool copyPath(const QString &src, const QString &dst, bool follow_symlinks = true); - -/** - * Delete a folder recursively - */ -MULTIMC_UTIL_EXPORT bool deletePath(QString path); - -/// Opens the given file in the default application. -MULTIMC_UTIL_EXPORT void openFileInDefaultProgram(QString filename); - -/// Opens the given directory in the default application. -MULTIMC_UTIL_EXPORT void openDirInDefaultProgram(QString dirpath, bool ensureExists = false); - -/// Checks if the a given Path contains "!" -MULTIMC_UTIL_EXPORT bool checkProblemticPathJava(QDir folder); diff --git a/depends/util/include/userutils.h b/depends/util/include/userutils.h deleted file mode 100644 index aadc112e..00000000 --- a/depends/util/include/userutils.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include <QString> - -#include "multimc_util_export.h" - -namespace Util -{ -// Get the Directory representing the User's Desktop -MULTIMC_UTIL_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 -MULTIMC_UTIL_EXPORT bool createShortCut(QString location, QString dest, QStringList args, - QString name, QString iconLocation); -} |