equal
deleted
inserted
replaced
37 #include "MapModel.h" |
37 #include "MapModel.h" |
38 #include "ThemeModel.h" |
38 #include "ThemeModel.h" |
39 |
39 |
40 DataManager::DataManager() |
40 DataManager::DataManager() |
41 { |
41 { |
42 m_userData = new QDir(cfgdir->absolutePath()); |
|
43 if (!m_userData->cd("Data")) |
|
44 m_userData = NULL; |
|
45 |
|
46 m_defaultData = new QDir(datadir->absolutePath()); |
|
47 |
|
48 m_hatModel = NULL; |
42 m_hatModel = NULL; |
49 m_mapModel = NULL; |
43 m_mapModel = NULL; |
50 m_themeModel = NULL; |
44 m_themeModel = NULL; |
51 m_colorsModel = NULL; |
45 m_colorsModel = NULL; |
52 m_bindsModel = NULL; |
46 m_bindsModel = NULL; |
64 const QString & subDirectory, |
58 const QString & subDirectory, |
65 QDir::Filters filters, |
59 QDir::Filters filters, |
66 const QStringList & nameFilters |
60 const QStringList & nameFilters |
67 ) const |
61 ) const |
68 { |
62 { |
69 QStringList result; |
63 QDir tmpDir(QString("physfs://%1").arg(subDirectory)); |
70 |
64 QStringList result = tmpDir.entryList(nameFilters, filters); |
71 if (m_userData != NULL) |
|
72 { |
|
73 QDir tmpDir(*m_userData); |
|
74 if (tmpDir.cd(subDirectory)) |
|
75 result.append(tmpDir.entryList(nameFilters, filters)); |
|
76 } |
|
77 |
|
78 QDir tmpDir(*m_defaultData); |
|
79 if (tmpDir.cd(subDirectory)) |
|
80 result.append(tmpDir.entryList(nameFilters, filters)); |
|
81 |
|
82 result.removeDuplicates(); |
|
83 |
65 |
84 // sort case-insensitive |
66 // sort case-insensitive |
85 QMap<QString, QString> sortedFileNames; |
67 QMap<QString, QString> sortedFileNames; |
86 foreach ( QString fn, result) |
68 foreach ( QString fn, result) |
87 { |
69 { |
94 |
76 |
95 |
77 |
96 QString DataManager::findFileForRead( |
78 QString DataManager::findFileForRead( |
97 const QString & relativeDataFilePath) const |
79 const QString & relativeDataFilePath) const |
98 { |
80 { |
99 QString path; |
81 QString path("physfs://%1"); |
100 |
82 |
101 if (m_userData != NULL) |
83 return path.arg(relativeDataFilePath); |
102 path = m_userData->absolutePath()+"/"+relativeDataFilePath; |
|
103 |
|
104 if ((!path.isEmpty()) && (!QFile::exists(path))) |
|
105 path = m_defaultData->absolutePath()+"/"+relativeDataFilePath; |
|
106 |
|
107 return path; |
|
108 } |
84 } |
109 |
85 |
110 |
86 |
111 QString DataManager::findFileForWrite( |
87 QString DataManager::findFileForWrite( |
112 const QString & relativeDataFilePath) const |
88 const QString & relativeDataFilePath) const |
113 { |
89 { |
114 if (m_userData != NULL) |
90 QString path("physfs://%1"); |
115 { |
|
116 QString path = m_userData->absolutePath()+"/"+relativeDataFilePath; |
|
117 |
91 |
118 // create folders if needed |
92 // create folders if needed |
119 QDir tmp; |
93 QDir tmp; |
120 tmp.mkpath(QFileInfo(path).absolutePath()); |
94 tmp.mkpath(QFileInfo(path.arg(relativeDataFilePath)).absolutePath()); |
121 |
95 |
122 return path; |
96 return path; |
123 } |
|
124 |
|
125 |
|
126 return ""; |
|
127 } |
97 } |
128 |
98 |
129 GameStyleModel * DataManager::gameStyleModel() |
99 GameStyleModel * DataManager::gameStyleModel() |
130 { |
100 { |
131 if (m_gameStyleModel == NULL) { |
101 if (m_gameStyleModel == NULL) { |