瀏覽代碼

BETA: Fix for cached HTML not being loaded:
* Thanks '''zatei''' for report, first fix implementation and tests.
* Closed #6162

Zoey76 13 年之前
父節點
當前提交
ed8f546fe5

+ 26 - 23
L2J_Server_BETA/java/com/l2jserver/gameserver/cache/HtmCache.java

@@ -99,7 +99,7 @@ public class HtmCache
 	
 	private void parseDir(File dir)
 	{
-		final File[] files = dir.listFiles(htmlFilter);
+		final File[] files = dir.listFiles();
 		for (File file : files)
 		{
 			if (!file.isDirectory())
@@ -115,36 +115,39 @@ public class HtmCache
 	
 	public String loadFile(File file)
 	{
+		if (!htmlFilter.accept(file))
+		{
+			return null;
+		}
+		
 		final String relpath = Util.getRelativePath(Config.DATAPACK_ROOT, file);
 		final int hashcode = relpath.hashCode();
 		String content = null;
-		if (htmlFilter.accept(file))
+		try (FileInputStream fis = new FileInputStream(file);
+			BufferedInputStream bis = new BufferedInputStream(fis);)
 		{
-			try (FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis);)
+			final int bytes = bis.available();
+			byte[] raw = new byte[bytes];
+			
+			bis.read(raw);
+			content = new String(raw, "UTF-8");
+			content = content.replaceAll("\r\n", "\n");
+			
+			String oldContent = _cache.get(hashcode);
+			if (oldContent == null)
 			{
-				final int bytes = bis.available();
-				byte[] raw = new byte[bytes];
-				
-				bis.read(raw);
-				content = new String(raw, "UTF-8");
-				content = content.replaceAll("\r\n", "\n");
-				
-				String oldContent = _cache.get(hashcode);
-				if (oldContent == null)
-				{
-					_bytesBuffLen += bytes;
-					_loadedFiles++;
-				}
-				else
-				{
-					_bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
-				}
-				_cache.put(hashcode, content);
+				_bytesBuffLen += bytes;
+				_loadedFiles++;
 			}
-			catch (Exception e)
+			else
 			{
-				_log.log(Level.WARNING, "Problem with htm file " + e.getMessage(), e);
+				_bytesBuffLen = (_bytesBuffLen - oldContent.length()) + bytes;
 			}
+			_cache.put(hashcode, content);
+		}
+		catch (Exception e)
+		{
+			_log.log(Level.WARNING, "Problem with htm file " + e.getMessage(), e);
 		}
 		return content;
 	}

+ 1 - 1
L2J_Server_BETA/java/com/l2jserver/util/file/filter/HTMLFilter.java

@@ -27,7 +27,7 @@ public class HTMLFilter implements FileFilter
 	@Override
 	public boolean accept(File f)
 	{
-		if (!f.exists() || f.isDirectory())
+		if ((f == null) || !f.exists() || f.isDirectory())
 		{
 			return false;
 		}