⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resourcemanager.java

📁 Vyger offers a D & D and Rogue-like environment in a graphical online roleplay game.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            return true;
        return false;
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** Creates external directories if needed (if we are in a JAR).
    */
     public void createExternalClientDirectories() {
        if( !inClientJar )
            return;

        new File( getExternalConfigsDir() ).mkdirs();
        new File( getExternalMacrosDir() ).mkdirs();
        new File( getExternalLogsDir() ).mkdirs();
        new File( getExternalServerConfigsDir() ).mkdirs();
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** Creates external directories if needed (if we are in a JAR).
    */
     public void createExternalServerDirectories() {
        if( !inServerJar )
            return;

        new File( getExternalConfigsDir() ).mkdirs();
        new File( getExternalLogsDir() ).mkdirs();
        new File( getExternalServerConfigsDir() ).mkdirs();
        new File( getExternalPlayersHomeDir() ).mkdirs();
        new File( getUniverseDataDir() ).mkdirs();
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To complete this directory name with the appropriate path begining.
    * @param dirName directory name of the resource directory
    */
     protected String getResourceDir( String dirName ) {
     	 if( inJar )
     	     return WOTLAS_JAR_ROOT_RESOURCE_DIR+"/"+dirName+"/";
         return basePath+File.separator+dirName+File.separator;
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To complete this external directory name with the appropriate path begining.
    *  By external we mean outside of the JAR if there is one. If there is none
    *  the directory returned is the same that would be returned by getResourceDir()
    *
    * @param dirName directory name of the resource directory
    * @return path ending with a "/"
    */
     protected String getExternalResourceDir( String dirName ) {
     	 if( inJar )
     	     return wotlasJarExternalDir+"/"+dirName+"/";
         return basePath+File.separator+dirName+File.separator;
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To get the Configs Directory (in the inside the eventual JAR).
    */
     public String getConfigsDir() {
     	 return getResourceDir( CONFIGS_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To get the External Configs Directory (external means outside the eventual JAR).
    */
     public String getExternalConfigsDir() {
     	 return getExternalResourceDir( CONFIGS_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To get the Fonts Directory.
    */
     public String getFontsDir() {
     	 return getResourceDir( FONTS_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /**  To get the GUI Images Directory.
    */
     public String getGuiImageDir() {
     	 return getResourceDir( GUI_IMAGES_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /**  To get the Image Library Directory.
    */
     public String getImageLibraryDir() {
     	 return getResourceDir( IMAGE_LIBRARY_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /**  To get the Logs Directory Name.
    */
     public String getExternalLogsDir() {
     	 return getExternalResourceDir( LOGS_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To get the Configs Macros Directory.
    */
     public String getExternalMacrosDir() {
     	 return getExternalResourceDir( MACROS_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /**  To get the Music Directory.
    */
     public String getMusicsDir() {
     	 return getResourceDir( MUSICS_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /**  To get the npc definition 
    */
     public String getNpcDataDir() {
     	 if( inJar )
     	     return getResourceDir( ENVIRONMENTS_DIR
             +"/"+EnvironmentManager.getEnvDir()
             +"/"+NPC_DEFINITION_DIR );
     	 return getResourceDir( ENVIRONMENTS_DIR
         +File.separator+EnvironmentManager.getEnvDir()
         +File.separator+NPC_DEFINITION_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /**  To get the editorbackup definition 
    */
     public String getEditorBackupDataDir() {
     	 if( inClientJar )
     	     return WOTLAS_JAR_ROOT_RESOURCE_DIR
             +"/"+ENVIRONMENTS_DIR
             +"/"+EnvironmentManager.getEnvDir()
             +"/"+this.EDITOR_BACKUP_DIR;
         else if( inServerJar )
     	     return wotlasJarExternalDir
             +"/"+ENVIRONMENTS_DIR
             +"/"+EnvironmentManager.getEnvDir()
             +"/"+this.EDITOR_BACKUP_DIR;

         return basePath
         +File.separator+ENVIRONMENTS_DIR
         +File.separator+EnvironmentManager.getEnvDir()
         +File.separator+EDITOR_BACKUP_DIR;         
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /**  To get the Home Directory (where players are stored)
    */
     public String getExternalPlayersHomeDir() {
     	 return getExternalResourceDir( PLAYERS_HOME_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To get the Server Configs Directory (outside the jar)
    */
     public String getExternalServerConfigsDir() {
     	 return getExternalResourceDir( SERVER_CONFIGS_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To get the GUI SMILEYS Images Directory.
    */
     public String getGuiSmileysDir() {
     	 return getResourceDir( SMILEYS_IMAGES_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To get the Sounds Directory.
    */
     public String getSoundsDir() {
     	 return getResourceDir( SOUNDS_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To get the Universe Data Directory. Server Universe data is always loaded from
    *  outside the eventual JAR.
    */
     public String getUniverseDataDir() {
     	 if( inClientJar )
     	     return WOTLAS_JAR_ROOT_RESOURCE_DIR
             +"/"+ ENVIRONMENTS_DIR 
             +"/"+ EnvironmentManager.getEnvDir()
             +"/"+UNIVERSE_DATA_DIR+"/";
         else if( inServerJar )
     	     return wotlasJarExternalDir
             +"/"+ ENVIRONMENTS_DIR 
             +"/"+EnvironmentManager.getEnvDir()
             +"/"+UNIVERSE_DATA_DIR+"/";

         return basePath
         +File.separator+ENVIRONMENTS_DIR
         +File.separator+EnvironmentManager.getEnvDir()
         +File.separator+UNIVERSE_DATA_DIR+File.separator;
/*
         if( inClientJar )
     	     return WOTLAS_JAR_ROOT_RESOURCE_DIR+"/"+UNIVERSE_DATA_DIR+"/";
         else if( inServerJar )
     	     return wotlasJarExternalDir+"/"+UNIVERSE_DATA_DIR+"/";

         return basePath+File.separator+UNIVERSE_DATA_DIR+File.separator;
 */
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To get the Wizard Steps Directory.
    */
     public String getWizardStepsDir() {
     	 return getResourceDir( WIZARD_STEPS_DIR );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To get the Layouts Directory.
    */
     public String getLayoutsDir() {
     	 return getResourceDir( LAYOUTS_DIR );
     }
     
 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To get Help Docs Directory.
    */
     public String getHelpDocsDir() {
         if(inJar)
            return WOTLAS_JAR_ROOT_DOCS_DIR+"/";
         return DEFAULT_HELP_DOCS_PATH+File.separator;
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To list all the files in the universe directory ( on one level only ).
    *  The provided dirName must be a directory/sub-directory name under the
    *  universe directory. Because we know we are in the Universe directory we
    *  can perform intelligent choices whether to search in a JAR or not :
    *  Server Universe data is ALWAYS outside the JAR.
    *
    *  @param dirName directory name (must be a complete path)
    *  @param ext extension of the files to search, enter "" to get all the files.
    *  @return the files (not sub-dirs) that have the specified extension.
    */
     public String[] listUniverseFiles( String dirName, String ext ) {
     	   if( ext==null )
     	       ext ="";
     	
           if( inClientJar ) {
               return Tools.listFilesInJar( jarName, dirName, ext );
           }
           else
               return FileTools.listFiles( dirName, ext );
     }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To list all the directories of a directory ( on one level only ).
    *  The provided dirName must be a directory/sub-directory name under the
    *  universe directory. Because we know we are in the Universe directory we
    *  can perform intelligent choices whether to search in a JAR or not :
    *  Server Universe data is ALWAYS outside the JAR.
    *
    *  @param dirName directory name (must be a complete path)
    *  @return the sub-dirs of the given dirName (on one level only).
    */
     public String[] listUniverseDirectories( String dirName ) {     	
           if( inClientJar ) {
               return Tools.listFilesInJar( jarName, dirName, null );
           }
           else
               return FileTools.listDirs( dirName  );
     }

  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To list all the directories of a directory ( on one level only ).
    *  The provided dirName must be a directory/sub-directory name under the
    *  universe directory. Because we know we are in the Universe directory we
    *  can perform intelligent choices whether to search in a JAR or not :
    *  Server Universe data is ALWAYS outside the JAR.
    *
    *  @param dirName directory name (must be a complete path)
    *  @return the sub-dirs of the given dirName (on one level only).
    */
     public String[] listUniverseDirectories( String dirName, String ext  ) {     	
     	   if( ext==null )
     	       ext ="";
           if( inClientJar ) {
               return Tools.listFilesInJar( jarName, dirName, ext );
           }
           else
               return FileTools.listDirs( dirName, ext );
     }

  /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

	   /** To load an object from a binary file. The filePath MUST be corresponding to a
		*  valid resource path.
		*
		* @param fileName a file name that has been appended to the end of a directory path
		*        provided by this ResourceManager.
		*/
		 public Object RestoreObject( String filePath ) {
			   if( inJar && !isExternal(filePath) ) {
				  InputStream is = this.getClass().getResourceAsStream( filePath );
				  if(is==null) return null;

				  Object o = null;

					try{
					   o = PropertiesConverter.Restore( is );
					}
					catch( PersistenceException pe ) {
					   Debug.signal( Debug.ERROR, this, pe );
					}

					try{
					   is.close();
					}catch(IOException e) {
					   e.printStackTrace();
					}

				  return o;
                           }
			   else {
					try{
					   return PropertiesConverter.Restore( filePath );
					}
					catch( PersistenceException pe ) {
					   Debug.signal( Debug.ERROR, this, ""+pe );
					   return null;
					}
			   }
		 }

 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

   /** To load an object from a property file. The filePath MUST be corresponding to a
    *  valid resource path.
    *
    * @param fileName a file name that has been appended to the end of a directory path
    *        provided by this ResourceManager.
    */
     public Object loadObject( String filePath ) {
           if( inJar && !isExternal(filePath) ) {
              InputStream is = this.getClass().getResourceAsStream( filePath );
              if(is==null) return null;

              Object o = null;

                try{
                   o = PropertiesConverter.load( is );
                }
                catch( PersistenceException pe ) {
                   Debug.signal( Debug.ERROR, this, pe );
                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -