OSDN Git Service

[denncoCreator] Some code refactoring to implement the feature to support external...
[dennco/denncoCreator.git] / Source / utils / dcutil.cpp
1 //  Copyright (c) 2012 Dennco Project
2 //
3 // This program is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 //
17 //  Created by tkawata on Oct-1, 2012.
18 //
19 #include "dcutil.h"
20
21 #include "DNUtils.h"
22
23 #include <QDir>
24 #include <QFileInfoList>
25
26 //static
27 void DCUtil::removeDirRecursive(QString path)
28 {
29     if (path.isEmpty() || path.length() == 0)
30         return;
31
32     QDir  dir(path);
33
34     QFileInfoList list = dir.entryInfoList(QDir::NoDot | QDir::NoDotDot | QDir::AllEntries);
35
36     for (int i = 0; i < list.length(); i++)
37     {
38         QFileInfo info = list.at(i);
39         if (info.isDir())
40         {
41             removeDirRecursive(info.absoluteFilePath());
42         }
43         else
44         {
45             QFile file(info.absoluteFilePath());
46             file.remove();
47         }
48     }
49     dir.rmdir(path);
50 }
51
52 //static
53 QString DCUtil::getFQNPath(const QString& containerBasedPath, const QString& name)
54 {
55     return QString::fromStdString(getFQNString(containerBasedPath.toLocal8Bit().data(), name.toLocal8Bit().data()));
56 }
57
58 //static
59 QString DCUtil::getFQNPath(std::string containerBasedPath, std::string name)
60 {
61     return QString::fromStdString(getFQNString(containerBasedPath.c_str(), name.c_str()));
62 }
63
64 //static
65 QString DCUtil::getNameFromFQNPath(const QString& fqnString)
66 {
67     if (fqnString.indexOf("#") >= 0)
68         return fqnString.mid(fqnString.indexOf("#")+1);
69     else
70         return "";
71 }
72
73 //static
74 QString DCUtil::getContainerBasedPathFromFQNPath(const QString& fqnPath)
75 {
76     if (fqnPath.indexOf("#") >= 0)
77         return fqnPath.left(fqnPath.indexOf("#"));
78     else
79         return "";
80 }