From 4dcd88ba599db03f7404e046a9b96c925c5f49fb Mon Sep 17 00:00:00 2001
From: jmarshallnz <jmarshallnz@svn>
Date: Sun, 4 Oct 2009 08:58:40 +0000
Subject: fixed: Cleaned up the DDSImage stuff so it can use our VFS.

git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@23407 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
---
 guilib/DDSImage.cpp                      | 30 ++++++++-----
 tools/TexturePacker/SimpleFS.h           | 72 ++++++++++++++++++++++++++++++++
 tools/TexturePacker/Win32/MakeDDS.vcproj |  8 ++--
 3 files changed, 95 insertions(+), 15 deletions(-)
 create mode 100644 tools/TexturePacker/SimpleFS.h

diff --git a/guilib/DDSImage.cpp b/guilib/DDSImage.cpp
index 0ddea6489a..80cc413f29 100644
--- a/guilib/DDSImage.cpp
+++ b/guilib/DDSImage.cpp
@@ -23,6 +23,13 @@
 #include "XBTF.h"
 #include <string.h>
 
+#ifndef NO_XBMC_FILESYSTEM
+#include "FileSystem/File.h"
+using namespace XFILE;
+#else
+#include "SimpleFS.h"
+#endif
+
 CDDSImage::CDDSImage()
 {
   m_data = NULL;
@@ -82,15 +89,15 @@ unsigned char *CDDSImage::GetData() const
 bool CDDSImage::ReadFile(const std::string &inputFile)
 {
   // open the file
-  FILE *file = fopen(inputFile.c_str(), "rb");
-  if (!file)
+  CFile file;
+  if (!file.Open(inputFile))
     return false;
 
   // read the header
   uint32_t magic;
-  if (fread(&magic, 4, 1, file) != 4)
+  if (file.Read(&magic, 4) != 4)
     return false;
-  if (fread(&m_desc, sizeof(m_desc), 1, file) != sizeof(m_desc))
+  if (file.Read(&m_desc, sizeof(m_desc)) != sizeof(m_desc))
     return false;
   if (!GetFormat())
     return false;  // not supported
@@ -101,25 +108,26 @@ bool CDDSImage::ReadFile(const std::string &inputFile)
     return false;
 
   // and read it in
-  if (fread(m_data, sizeof(m_data), 1, file) != sizeof(m_data))
+  if (file.Read(m_data, m_desc.linearSize) != m_desc.linearSize)
     return false;
 
+  file.Close();
   return true;
 }
 
 bool CDDSImage::WriteFile(const std::string &outputFile) const
 {
   // open the file
-  FILE *file = fopen(outputFile.c_str(), "wb");
-  if (!file)
+  CFile file;
+  if (!file.OpenForWrite(outputFile, true))
     return false;
 
   // write the header
-  fwrite("DDS ", 4, 1, file);
-  fwrite(&m_desc, sizeof(m_desc), 1, file);
+  file.Write("DDS ", 4);
+  file.Write(&m_desc, sizeof(m_desc));
   // now the data
-  fwrite(m_data, m_desc.linearSize, 1, file);
-  fclose(file);
+  file.Write(m_data, m_desc.linearSize);
+  file.Close();
   return true;
 }
 
diff --git a/tools/TexturePacker/SimpleFS.h b/tools/TexturePacker/SimpleFS.h
new file mode 100644
index 0000000000..33eebd6bec
--- /dev/null
+++ b/tools/TexturePacker/SimpleFS.h
@@ -0,0 +1,72 @@
+#pragma once
+
+/*
+ *      Copyright (C) 2005-2009 Team XBMC
+ *      http://www.xbmc.org
+ *
+ *  This Program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2, or (at your option)
+ *  any later version.
+ *
+ *  This Program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with XBMC; see the file COPYING.  If not, write to
+ *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  http://www.gnu.org/copyleft/gpl.html
+ *
+ */
+
+#include <stdio.h>
+#include <string>
+#include <stdint.h>
+
+class CFile
+{
+public:
+  CFile()
+  {
+    m_file = NULL;
+  }
+
+  bool Open(const std::string &file)
+  {
+    Close();
+    m_file = fopen(file.c_str(), "rb");
+    return NULL != m_file;
+  }
+
+  bool OpenForWrite(const std::string &file, bool overwrite)
+  {
+    Close();
+    m_file = fopen(file.c_str(), "wb");
+    return NULL != m_file;
+  }
+  void Close()
+  {
+    if (m_file)
+      fclose(m_file);
+    m_file = NULL;
+  }
+
+  uint64_t Read(void *data, uint64_t size)
+  {
+    if (fread(data, size, 1, m_file) == 1)
+      return size;
+    return 0;
+  }
+
+  uint64_t Write(const void *data, uint64_t size)
+  {
+    if (fwrite(data, size, 1, m_file) == 1)
+      return size;
+    return 0;
+  }
+
+private:
+  FILE* m_file;
+};
diff --git a/tools/TexturePacker/Win32/MakeDDS.vcproj b/tools/TexturePacker/Win32/MakeDDS.vcproj
index 814c2339a5..72852f74bf 100644
--- a/tools/TexturePacker/Win32/MakeDDS.vcproj
+++ b/tools/TexturePacker/Win32/MakeDDS.vcproj
@@ -41,8 +41,8 @@
 			<Tool
 				Name="VCCLCompilerTool"
 				Optimization="0"
-				AdditionalIncludeDirectories="..\..\..\xbmc\win32;..\..\..\guilib;..\..\..\xbmc\lib\libsquish"
-				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+				AdditionalIncludeDirectories="..;..\..\..\xbmc\win32;..\..\..\guilib;..\..\..\xbmc\lib\libsquish"
+				PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;NO_XBMC_FILESYSTEM"
 				MinimalRebuild="true"
 				BasicRuntimeChecks="3"
 				RuntimeLibrary="3"
@@ -116,8 +116,8 @@
 				Name="VCCLCompilerTool"
 				Optimization="2"
 				EnableIntrinsicFunctions="true"
-				AdditionalIncludeDirectories="..\..\..\xbmc\win32;..\..\..\guilib;..\..\..\xbmc\lib\libsquish"
-				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+				AdditionalIncludeDirectories="..;..\..\..\xbmc\win32;..\..\..\guilib;..\..\..\xbmc\lib\libsquish"
+				PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;NO_XBMC_FILESYSTEM"
 				RuntimeLibrary="2"
 				EnableFunctionLevelLinking="true"
 				UsePrecompiledHeader="0"
-- 
cgit v1.2.3