// Check whether the file has changed on disk // by looking at the time stamp bool GLEFileInfo::hasChanged() { QFileInfo fi; QString mainFile(primaryFile()); if (mainFile.isEmpty()) { return false; } fi.setFile(mainFile); if (!fi.isReadable()) { return false; } QDateTime modifiedTime(fi.lastModified()); if (modifiedTime > lastModified) { return true; } else { for (int i = 0; i < filesToMonitor.size(); ++i) { GLEFileData data(filesToMonitor.at(i)); fi.setFile(data.fname); if (fi.isReadable() && fi.lastModified() > data.lastModified) { return true; } } return false; } }
int main(int argc, char *argv[]) { // Задание кодировки приложения #ifndef QT_NO_TEXTCODEC QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); #endif /// Параметр -debug влияет на вывод qDebug() в консоль. parseArg(argc, argv); QApplication app(argc, argv); // Заполняем глобальные переменные QFileInfo mainFile(app.applicationFilePath()); if (app.applicationName().isEmpty()) { app.setApplicationName( mainFile.baseName() ); } if (app.applicationVersion().isEmpty()) { qApp->setApplicationVersion(QString("%1.%2.%3").arg(VERSION_MAJOR).arg(VERSION_MINOR).arg(VERSION_PATCH)); } QDir *mainDir = new QDir(SettingsFile::getDefaultUserDataPath()); mainDir->mkpath(mainDir->path()); delete mainDir; // Перенаправляем вывод отладочной информации в файл // On Unix: Projects > Run Settings > Run in terminal qInstallMsgHandler(myMessageOutput); // Инициируем перевод через Qt Linguist const QString localeFile = SettingsFile::getDefaultResourcePath() + "/translations/" + mainFile.baseName() + "_" + QLocale::system().name(); QTranslator translator; if (!translator.load( localeFile )) { qDebug() << "Can't load QM (TS):" << localeFile; } app.installTranslator(&translator); // Для Win32 указываем искать плагины в директории с приложением #if defined(Q_WS_WIN32) app.addLibraryPath(app.applicationDirPath()); #endif MainWindow w; w.show(); return app.exec(); }
/* Create a new project. - a new directory for the project - an XML project file for the project, from template - a stubbed out source file, from template Make sure the path name doesn't have any spaces in it, so make can work happily. Return the new project's name, or an empty string on failure. */ QString ProjectManager::createNewProject(const QString & newProjectPath) { QString projectPath = confirmValidProjectName(newProjectPath); QDir newProjectDir; newProjectDir.mkpath(projectPath); newProjectDir.setPath(projectPath); QString newProjName = newProjectDir.dirName(); // grab the templates for a new project QString templatePath = "resources/templates"; #ifdef MCBUILDER_TEST_SUITE templatePath.prepend("../"); #endif QDir templatesDir(MainWindow::appDirectory().filePath(templatePath)); // create the project file from our template QFile templateFile(templatesDir.filePath("project_template.xml")); templateFile.copy(newProjectDir.filePath(newProjName + ".xml")); templateFile.close(); templateFile.setFileName(templatesDir.filePath("makefile_template.txt")); templateFile.copy(newProjectDir.filePath("Makefile")); templateFile.close(); templateFile.setFileName(templatesDir.filePath("config_template.txt")); templateFile.copy(newProjectDir.filePath("config.h")); templateFile.close(); templateFile.setFileName(templatesDir.filePath("source_template.txt")); if (templateFile.open(QIODevice::ReadOnly | QFile::Text)) { // and create the main file QFile mainFile(newProjectDir.filePath(newProjName + ".c")); if (mainFile.open(QIODevice::WriteOnly | QFile::Text)) { QTextStream out(&mainFile); out << QString("// %1.c").arg(newProjName) << endl; out << QString("// created %1").arg(QDate::currentDate().toString("MMM d, yyyy") ) << endl; out << templateFile.readAll(); mainFile.close(); } QFileInfo fi(mainFile); addToProjectFile(newProjectDir.path(), fi.filePath()); templateFile.close(); } return newProjectDir.path(); }
int main(int argc, char **argv) { QApplication app(argc, argv); QWidget window; QTextEdit editor; QFile mainFile("./main.rb"); mainFile.open(QIODevice::ReadOnly | QIODevice::Text); editor.setPlainText(mainFile.readAll()); Runner runner; MyPushButton helloButton(runner, "Run", editor); helloButton.resize(100, 30); MyPushButton::connect(&helloButton, SIGNAL (clicked()), &helloButton, SLOT (handleClicked())); QPushButton stopButton("Stop"); stopButton.resize(100, 30); QPushButton::connect(&stopButton, SIGNAL (clicked()), &runner, SLOT (Stop())); QHBoxLayout mainLayout; QVBoxLayout editorLayout; editorLayout.addWidget(&editor); editorLayout.addWidget(&helloButton); editorLayout.addWidget(&stopButton); QGraphicsScene scene(0, 0, 600, 600); Drawing::Init(&scene); QGraphicsView sceneView(&scene); sceneView.setMinimumSize(610, 610); mainLayout.addLayout(&editorLayout); mainLayout.addWidget(&sceneView); window.setLayout(&mainLayout); window.show(); return app.exec(); }
/* Create a new project. - a new directory for the project - an XML project file for the project, from template - a stubbed out source file, from template Make sure the path name doesn't have any spaces in it, so make can work happily. Return the new project's name, or an empty string on failure. */ QString ProjectManager::createNewProject(QString newProjectPath) { confirmValidProjectName(&newProjectPath); if(newProjectPath.contains(" ")) // if there are still spaces in the path, we have problems return ""; QDir newProjectDir; newProjectDir.mkpath(newProjectPath); newProjectDir.setPath(newProjectPath); QString newProjName = newProjectDir.dirName(); // grab the templates for a new project QDir templatesDir = QDir::current().filePath("resources/templates"); // create the project file from our template QFile templateFile(templatesDir.filePath("project_template.xml")); templateFile.copy(newProjectDir.filePath(newProjName + ".xml")); templateFile.close(); templateFile.setFileName(templatesDir.filePath("source_template.txt")); if( templateFile.open(QIODevice::ReadOnly | QFile::Text) ) { // and create the main file QFile mainFile(newProjectDir.filePath(newProjName + ".c")); if( mainFile.open(QIODevice::WriteOnly | QFile::Text) ) { QTextStream out(&mainFile); out << QString("// %1.c").arg(newProjName) << endl; out << QString("// created %1").arg(QDate::currentDate().toString("MMM d, yyyy") ) << endl; out << templateFile.readAll(); mainFile.close(); } QFileInfo fi(mainFile); addToProjectFile(newProjectDir.path(), fi.filePath(), "thumb"); templateFile.close(); } return newProjectDir.path(); }
void ProjectManager::onNewProject(QString name, QString logicFile, QString directory) { if(name.isEmpty()) { QString errorMsg("Please enter a name for your project."); emit(createProjectFailed(errorMsg)); return; } if(logicFile.isEmpty()) { QString errorMsg("Please enter a name for the main logic file of your project."); emit(createProjectFailed(errorMsg)); return; } if(!logicFile.endsWith(".js", Qt::CaseInsensitive)) { logicFile += ".js"; } QUrl url = QUrl(directory); if(!url.isValid() || url.isEmpty()) { QString errorMsg = QString("Directory at %1 is not a valid directory.") .arg(url.toLocalFile()); emit(createProjectFailed(errorMsg)); return; } QDir dir(url.toLocalFile()); if(!dir.exists()) { QString errorMsg = QString("Project directory at %1 doesn't exist.") .arg(url.toLocalFile()); emit(createProjectFailed(errorMsg)); return; } QString encodedName = QUrl::toPercentEncoding(name); if(!dir.mkdir(encodedName)) { QString errorMsg = QString("Failed to create new project directory at %1/%2.") .arg(url.toLocalFile()) .arg(encodedName); emit(createProjectFailed(errorMsg)); return; } dir.cd(encodedName); dir.absolutePath(); QString projectFileName = dir.absolutePath() + "/project.js"; QFile projectFile(projectFileName); if(!projectFile.open(QIODevice::ReadWrite)) { QString errorMsg = QString("Failed to open the new project file at %1.") .arg(projectFileName); emit(createProjectFailed(errorMsg)); return; } QString newProjectContent = QString(sNewProjectTemplate).arg(name) .arg(logicFile); projectFile.write(newProjectContent.toLocal8Bit()); projectFile.close(); QString encodedLogic = QUrl::toPercentEncoding(logicFile); QString mainFileName = dir.absolutePath() + "/" + encodedLogic; QFile mainFile(mainFileName); if(!mainFile.open(QIODevice::ReadWrite)) { QString errorMsg = QString("Failed to open the new project file at %1.") .arg(mainFileName); emit(createProjectFailed(errorMsg)); return; } mainFile.write(sLogicFileTemplate.toLocal8Bit()); mainFile.close(); }
int main( int argc, char *argv[] ) { ASSERT( argc > 2, "merge [main file].x [anim file].x [name]" ); std::fstream mainFile( argv[1] ); ASSERT( mainFile.is_open(), std::string( "unable to open " ) + argv[1] + " file" ); std::ifstream animFile( argv[2] ); ASSERT( mainFile.is_open(), std::string( "unable to open " ) + argv[2] + " file" ); std::string setName; std::string baseName; // find the animation set in the anim file MovePastNext( animFile, "AnimationSet" ); int readPos = MovePastNext( animFile, "AnimationSet" ); animFile >> baseName; setName = ( argc > 3 ) ? argv[3] : baseName; animFile.seekg( readPos ); std::string header( "AnimationSet " + baseName ); int headerLen = (int)header.length() + 1; char *animSet; int animSetSize = ReadAnimSet( animSet, animFile, readPos + headerLen, setName ); int headerPos = -1; int writePos = -1; int backupPos = 0; // find position to insert animation set MovePastNext( mainFile, "AnimationSet" ); while ( !mainFile.eof() ) { headerPos = MovePastNext( mainFile, "AnimationSet" ); if ( headerPos == -1 ) break; std::string buf(""); mainFile >> buf; if ( buf == setName ) { backupPos = MovePastNext( mainFile, "AnimationSet" ); break; } } char *backup = NULL; int backupSize = 0; int endOfFile = 0; header = "AnimationSet " + setName; headerLen = (int)header.length() + 1; writePos = headerPos + headerLen; if ( headerPos == -1 ) { mainFile.clear(); mainFile.seekp( 0, std::ios_base::end ); } else { mainFile.seekg( 0, std::ios_base::end ); endOfFile = (int)mainFile.tellg(); backupSize = endOfFile - backupPos; backup = new char[backupSize]; mainFile.seekg( backupPos ); mainFile.read( backup, backupSize ); mainFile.clear(); // failbit will most likely be set from last read mainFile.seekp( headerPos ); } char newLine = '\n'; mainFile.write( &newLine, sizeof( newLine ) ); mainFile.write( animSet, animSetSize ); mainFile.write( &newLine, sizeof( newLine ) ); mainFile.write( &newLine, sizeof( newLine ) ); if ( backup ) { int last = backupSize - 1; while ( backup[last--] != '}' ) ; mainFile.write( backup, last + 2 ); int curPos = mainFile.tellp(); if ( curPos < endOfFile ) { int nEmptyBytes = endOfFile - curPos + 1; char *emptySpace = new char[nEmptyBytes]; memset( emptySpace, ' ', nEmptyBytes ); mainFile.write( emptySpace, nEmptyBytes ); SAFE_DELETE_ARRAY( emptySpace ); } } std::cout << "done" << std::endl; mainFile.close(); animFile.close(); SAFE_DELETE_ARRAY( animSet ); SAFE_DELETE_ARRAY( backup ); return 0; }