bool TupFileManager::save(const QString &fileName, TupProject *project) { #ifdef K_DEBUG QString msg = "TupFileManager::save() - Saving file -> " + fileName; #ifdef Q_OS_WIN32 qWarning() << msg; #else tWarning() << msg; #endif #endif /* int indexPath = fileName.lastIndexOf(QDir::separator()); int indexFile = fileName.length() - indexPath; QString name = fileName.right(indexFile - 1); int indexDot = name.lastIndexOf("."); name = name.left(indexDot); */ QFileInfo info(fileName); QString name = info.baseName(); QString oldDirName = CACHE_DIR + project->projectName(); QDir projectDir(oldDirName); if (name.compare(project->projectName()) != 0) { project->setProjectName(name); projectDir.setPath(CACHE_DIR + name); project->library()->updatePaths(CACHE_DIR + name); if (!projectDir.exists()) { if (projectDir.rename(oldDirName, projectDir.path())) { #ifdef K_DEBUG QString msg = "TupFileManager::save() - Directory renamed to -> " + projectDir.path(); #ifdef Q_OS_WIN32 qWarning() << msg; #else tWarning() << msg; #endif #endif } else { // SQA: Check if these lines are really needed if (! projectDir.mkdir(projectDir.path())) { #ifdef K_DEBUG QString msg = "TupFileManager::save() - Error: Can't create path -> " + projectDir.path(); #ifdef Q_OS_WIN32 qDebug() << msg; #else tError() << msg; #endif #endif return false; } else { #ifdef K_DEBUG QString msg = "TupFileManager::save() - Directory was created successfully -> " + projectDir.path(); #ifdef Q_OS_WIN32 qWarning() << msg; #else tWarning() << msg; #endif #endif } } } } else { if (!projectDir.exists()) { if (! projectDir.mkdir(projectDir.path())) { #ifdef K_DEBUG QString msg = "TupFileManager::save() - Error: Can't create path -> " + projectDir.path(); #ifdef Q_OS_WIN32 qDebug() << msg; #else tError() << msg; #endif #endif return false; } else { #ifdef K_DEBUG QString msg = "TupFileManager::save() - Directory was created successfully -> " + projectDir.path(); #ifdef Q_OS_WIN32 qWarning() << msg; #else tWarning() << msg; #endif #endif } } } { // Save project QFile projectFile(projectDir.path() + QDir::separator() + "project.tpp"); if (projectFile.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream ts(&projectFile); QDomDocument doc; project->setProjectName(name); doc.appendChild(project->toXml(doc)); ts << doc.toString(); projectFile.close(); } else { #ifdef K_DEBUG QString msg = "TupFileManager::save() - Error: Can't create file -> " + projectDir.path() + QDir::separator() + "project.tpp"; #ifdef Q_OS_WIN32 qDebug() << msg; #else tError() << msg; #endif #endif } } // Save scenes { int index = 0; int totalScenes = project->scenes().size(); for (int i = 0; i < totalScenes; i++) { TupScene *scene = project->scenes().at(i); QDomDocument doc; doc.appendChild(scene->toXml(doc)); QString scenePath = projectDir.path() + QDir::separator() + "scene" + QString::number(index) + ".tps"; QFile sceneFile(scenePath); if (sceneFile.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream st(&sceneFile); st << doc.toString(); index += 1; sceneFile.close(); } else { #ifdef K_DEBUG QString msg = "TupFileManager::save() - Error: Can't create file -> " + scenePath; #ifdef Q_OS_WIN32 qDebug() << msg; #else tError() << msg; #endif #endif } } } { // Save library QFile lbr(projectDir.path() + QDir::separator() + "library.tpl"); if (lbr.open(QIODevice::WriteOnly | QIODevice::Text)) { QTextStream ts(&lbr); QDomDocument doc; doc.appendChild(project->library()->toXml(doc)); ts << doc.toString(); lbr.close(); } else { #ifdef K_DEBUG QString msg = "TupFileManager::save() - Error: Can't create file -> " + projectDir.path() + QDir::separator() + "library.tpl"; #ifdef Q_OS_WIN32 qDebug() << msg; #else tError() << msg; #endif #endif } } TupPackageHandler packageHandler; bool ok = packageHandler.makePackage(projectDir.path(), fileName); if (ok) { #ifdef K_DEBUG QString msg = "TupFileManager::save() - Project saved in -> " + fileName; #ifdef Q_OS_WIN32 qWarning() << msg; #else tWarning() << msg; #endif #endif } else { #ifdef K_DEBUG QString msg = "TupFileManager::save() - Error: Project couldn't be saved in -> " + fileName; #ifdef Q_OS_WIN32 qDebug() << msg; #else tError() << msg; #endif #endif } return ok; }
void CtrlMemView::paintEvent(QPaintEvent *) { QPainter painter(this); painter.setBrush(Qt::white); painter.setPen(Qt::white); painter.drawRect(rect()); if (!debugger) return; int width = rect().width(); int numRows=(rect().bottom()/rowHeight)/2+1; QPen nullPen(0xFFFFFF); QPen currentPen(0xFF000000); QPen selPen(0x808080); QBrush lbr(0xFFFFFF); QBrush nullBrush(0xFFFFFF); QBrush currentBrush(0xFFEFE8); QBrush pcBrush(0x70FF70); QPen textPen; QFont normalFont("Arial", 10); QFont alignedFont("Monospace", 10); alignedFont.setStyleHint(QFont::Monospace); painter.setFont(normalFont); int i; curAddress&=~(align-1); for (i=-numRows; i<=numRows; i++) { unsigned int address=curAddress + i*align*alignMul; int rowY1 = rect().bottom()/2 + rowHeight*i - rowHeight/2; int rowY2 = rect().bottom()/2 + rowHeight*i + rowHeight/2; char temp[256]; painter.setBrush(currentBrush); if (selecting && address == (unsigned int)selection) painter.setPen(selPen); else painter.setPen(i==0 ? currentPen : nullPen); painter.drawRect(0, rowY1, 16-1, rowY2 - rowY1 - 1); painter.drawRect(16, rowY1, width - 16 -1, rowY2 - rowY1 - 1); painter.setBrush(nullBrush); textPen.setColor(0x600000); painter.setPen(textPen); painter.setFont(alignedFont); painter.drawText(17,rowY1-2+rowHeight, QString("%1").arg(address,8,16,QChar('0'))); textPen.setColor(0xFF000000); painter.setPen(textPen); if (debugger->isAlive()) { switch(mode) { case MV_NORMAL: { const char *m = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; if (Memory::IsValidAddress(address)) { u32 memory[4] = { debugger->readMemory(address), debugger->readMemory(address+4), debugger->readMemory(address+8), debugger->readMemory(address+12) }; m = (const char*)memory; sprintf(temp, "%08x %08x %08x %08x ................", memory[0],memory[1],memory[2],memory[3]); } for (int i=0; i<16; i++) { int c = (unsigned char)m[i]; if (c>=32 && c<255) temp[i+37]=c; } } painter.setFont(alignedFont); painter.drawText(85,rowY1 - 2 + rowHeight, temp); break; case MV_SYMBOLS: { /* textPen.setColor(0x0000FF); painter.setPen(textPen); int fn = g_symbolMap->GetSymbolNum(address); if (fn==-1) { sprintf(temp, "%s (ns)", Memory::GetAddressName(address)); } else sprintf(temp, "%s (0x%x b)", g_symbolMap->GetSymbolName(fn),g_symbolMap->GetSymbolSize(fn)); painter.drawText(205,rowY1 - 2 + rowHeight, temp); textPen.setColor(0xFF000000); painter.setPen(textPen); if (align==4) { u32 value = Memory::ReadUnchecked_U32(address); int symbolnum = g_symbolMap->GetSymbolNum(value); if(symbolnum>=0) sprintf(temp, "%08x [%s]", value, g_symbolMap->GetSymbolName(symbolnum)); } else if (align==2) { u16 value = Memory::ReadUnchecked_U16(address); int symbolnum = g_symbolMap->GetSymbolNum(value); if(symbolnum>=0) sprintf(temp, "%04x [%s]", value, g_symbolMap->GetSymbolName(symbolnum)); } painter.drawText(85,rowY1 - 2 + rowHeight, temp);*/ break; } case MV_MAX: break; } } } }