[PC-BSD Commits] r17583 - pcbsd/current/src-qt4/EasyPBI

svn at pcbsd.org svn at pcbsd.org
Mon Jul 2 14:40:05 PDT 2012


Author: kenmoore
Date: 2012-07-02 21:40:03 +0000 (Mon, 02 Jul 2012)
New Revision: 17583

Modified:
   pcbsd/current/src-qt4/EasyPBI/mainwindow.cpp
   pcbsd/current/src-qt4/EasyPBI/modBuild.cpp
   pcbsd/current/src-qt4/EasyPBI/modBuild.h
Log:
Setup EasyPBI to now properly overwrite modules (if desired)



Modified: pcbsd/current/src-qt4/EasyPBI/mainwindow.cpp
===================================================================
--- pcbsd/current/src-qt4/EasyPBI/mainwindow.cpp	2012-07-02 19:55:13 UTC (rev 17582)
+++ pcbsd/current/src-qt4/EasyPBI/mainwindow.cpp	2012-07-02 21:40:03 UTC (rev 17583)
@@ -200,6 +200,19 @@
 
 void MainWindow::on_create_button_clicked()
 {
+    //Check if this module already exists
+    QDir dir(MODOUT_DIR);
+    QString modDir = ui->port_selected->text().section("/",-1);
+    if(dir.exists(modDir)){
+      QMessageBox verify;
+      verify.setText(tr("A module for this port already exists."));
+      verify.setInformativeText(tr("Do you wish to replace the current module?"));
+      verify.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
+      verify.setDefaultButton(QMessageBox::Yes);
+      int ret = verify.exec();
+      if(ret != QMessageBox::Yes){return;}
+    }
+
     // Build Module
     bool success = FALSE;
     ModBuild::makeStructs(ui->port_name->text(),ui->website->text(),ui->author->text(), \

Modified: pcbsd/current/src-qt4/EasyPBI/modBuild.cpp
===================================================================
--- pcbsd/current/src-qt4/EasyPBI/modBuild.cpp	2012-07-02 19:55:13 UTC (rev 17582)
+++ pcbsd/current/src-qt4/EasyPBI/modBuild.cpp	2012-07-02 21:40:03 UTC (rev 17583)
@@ -146,26 +146,32 @@
       qDebug() << "Error: Directory exists, but is not a valid module";
       // return empty path
     }else{
-      qDebug() << "Valid Module directory already exists";
-      modulePath = baseDir + "/" + modName; //return the full path
+      qDebug() << "Valid Module directory already exists - overwriting it";
+      bool success = emptyDirectory(baseDir+"/"+modName); //Remove the module
+      if(!success){
+        qDebug() << " - Could not remove all old module contents. Please remove them by hand";
+      }else{
+        dir.rmdir(baseDir+"/"+modName);
+      }
     }
+  }
+  //Create New module directory
+  dir.cd(baseDir);
+  if(!dir.mkdir(modName)){
+    qDebug() << "Error: Could not create module directory";
+    // return empty path
   }else{
-    //New module directory
-    if(!dir.mkdir(modName)){
-      qDebug() << "Error: Could not create module directory";
-      // return empty path
-    }else{
-      //If main directory could be created, should no problem with sub-directories
-      dir.cd(modName);
-      dir.mkdir("resources");
-      dir.mkdir("xdg-desktop");
-      dir.mkdir("xdg-menu");
-      dir.mkdir("xdg-mime");
-      dir.mkdir("scripts");
-      qDebug() << "Module directory successfully created";
-      modulePath = baseDir + "/" + modName; //return the full path
-    }
+    //If main directory could be created, should no problem with sub-directories
+    dir.cd(modName);
+    dir.mkdir("resources");
+    dir.mkdir("xdg-desktop");
+    dir.mkdir("xdg-menu");
+    dir.mkdir("xdg-mime");
+    dir.mkdir("scripts");
+    qDebug() << "Module directory successfully created";
+    modulePath = baseDir + "/" + modName; //return the full path
   }
+
   return modulePath;
 }
 bool ModBuild::writePBIconf(QString modDir){
@@ -903,3 +909,27 @@
   
   return mc;
 }
+
+bool ModBuild::emptyDirectory(QString fullPath){
+  if(fullPath.endsWith("/")){ fullPath.chop(1); }
+  QDir rDir(fullPath);
+  bool success = TRUE;
+  //Remove files
+  QStringList cleanFiles = rDir.entryList(QDir::Files | QDir::NoDotAndDotDot);
+  for(int j=0; j<cleanFiles.length(); j++){ 
+    bool done = rDir.remove(cleanFiles[j]); 
+    if(!done) { 
+      qDebug() << " - File could not be deleted:" << fullPath+"/"+cleanFiles[j]; 
+      success=FALSE;
+    }  
+  }
+  //Remove Directories
+  cleanFiles = rDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
+  for(int j=0; j<cleanFiles.length(); j++){ 
+  bool isempty = emptyDirectory(fullPath+"/"+cleanFiles[j]); //This is recursive - be careful!!
+  if(isempty){ rDir.rmdir(cleanFiles[j]); } //only try to remove it if it is empty
+    else{ success=FALSE; }
+  }
+  //Return the result status
+  return success;
+}

Modified: pcbsd/current/src-qt4/EasyPBI/modBuild.h
===================================================================
--- pcbsd/current/src-qt4/EasyPBI/modBuild.h	2012-07-02 19:55:13 UTC (rev 17582)
+++ pcbsd/current/src-qt4/EasyPBI/modBuild.h	2012-07-02 21:40:03 UTC (rev 17583)
@@ -13,6 +13,7 @@
   static bool isGoodPort(QString, bool);
   static QString assignPortMenuCategory(QString);
   static int readMakeFile(QString);
+  static bool emptyDirectory(QString);
 
 public:
   static void makeStructs(QString,QString,QString,QString,QString,QString,QString,QString,QString,bool,QString,bool);



More information about the Commits mailing list