home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2014 January / PCgo_CD_14_01.iso / interface / lib / FileUtils.js < prev    next >
Encoding:
Text File  |  2013-04-10  |  2.7 KB  |  115 lines

  1. /**
  2.  * Diese Klasse beinhaltet Methoden f├╝r das File-Handling
  3.  * 
  4.  * @namespace IM
  5.  * @class FileUtils
  6.  * @constructor
  7.  */
  8. IM.FileUtils = function () {
  9.     /**
  10.      * NodeJS: Setzt die gui-Lib aus der globalen Konfiguration
  11.      * @property gui
  12.      * @type Object
  13.      * @private 
  14.      */
  15.     var gui = IM.Config.gui,
  16.     
  17.     /**
  18.      * NodeJS: Setzt die path-Lib aus der globalen Konfiguration
  19.      * @property path
  20.      * @type Object
  21.      * @private 
  22.      */
  23.     path = IM.Config.path,
  24.     
  25.     /**
  26.      * NodeJS: Setzt die fs-Lib aus der globalen Konfiguration
  27.      * @property fs
  28.      * @type Object
  29.      * @private 
  30.      */
  31.     fs = IM.Config.fs;
  32.     
  33.     /**
  34.      * Baut den Pfad zur Datei und wenn diese existiert wird ein Objekt mit entsprechenden Daten zur├╝ckgegeben.
  35.      * @method _getFilePath
  36.      * @param {String} file Der relative Pfad zur Datei
  37.      * @private
  38.      * @return {Object} Das Object beinhaltet 2 Variablen ( fileExists, filePath ).
  39.      */
  40.     var _getFilePath = function ( file ) {
  41.         /**
  42.          * Speichert und setzt den Pfad zur Datei
  43.          * @property filePath
  44.          * @type String
  45.          * @private 
  46.          */
  47.         var filePath = path.join( path.dirname( process.execPath ), file ),
  48.         
  49.         /**
  50.          * Speichert und pr├╝ft die Existenz der jeweiligen Datei
  51.          * @property fileExists
  52.          * @type Boolean
  53.          * @private
  54.          */
  55.         fileExists = fs.existsSync( filePath ),
  56.         
  57.         /**
  58.          * Speichert den Wert des zur├╝ckgegebenen Wertes.
  59.          * @property result
  60.          * @type Object
  61.          * @private 
  62.          */
  63.         result = {
  64.             fileExists: fileExists,
  65.             filePath: filePath
  66.         };
  67.             
  68.         return result;
  69.     };
  70.     
  71.     /**
  72.      * ├ûffnet eine Datei (file)
  73.      * @method openFile
  74.      * @param {String} file Der relative Pfad zur Datei
  75.      */
  76.     this.openFile = function ( file ) {
  77.         /**
  78.          * Speichert das Ergebnis der Methode _getFilePath
  79.          * @property fileInfo
  80.          * @type Object
  81.          * @private 
  82.          */
  83.         var fileInfo = _getFilePath( 'interface' + file );
  84.         
  85.         if( fileInfo.fileExists ) {
  86.             gui.Shell.openItem( fileInfo.filePath );
  87.         } else {
  88.             IM.ErrorHandler.errorMsg( 'Datei "' + file + '" wurde nicht gefunden.', 'type' );
  89.         }
  90.     };
  91.     
  92.     /**
  93.      * ├ûffnet den Ordner der Datei (file) im Dateibrowser
  94.      * @method openFileDir
  95.      * @param {String} file Der relative Pfad zur Datei
  96.      */
  97.     this.openFileDir = function ( file ) {
  98.         var fileInfo = _getFilePath( 'interface' + file );
  99.         
  100.         if( fileInfo.fileExists ) {
  101.             gui.Shell.showItemInFolder( fileInfo.filePath );
  102.         } else {
  103.             IM.ErrorHandler.errorMsg( 'Der Ordner konnte nicht ge├╢ffnet werden, da die Datei "' + file + '" nicht gefunden wurde.', 'type' );
  104.         }
  105.     };
  106.     
  107.     /**
  108.      * ├ûffnet eine URL im Standardbrowser des Systems
  109.      * @method openLink
  110.      * @param {String} url Die zu ├╢ffnende URL 
  111.      */
  112.     this.openLink = function ( url ) {
  113.         gui.Shell.openExternal( url );
  114.     };
  115. };