summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Lioncash2014-09-21 16:35:27 -0400
committerGravatar Lioncash2014-09-21 18:36:14 -0400
commitff442d6cf906fc4f30a99d8ccaa7e16c742cabcc (patch)
tree839e34582b3341663503384a682fb060409bddf0
parentMerge pull request #70 from linkmauve/master (diff)
downloadyuzu-ff442d6cf906fc4f30a99d8ccaa7e16c742cabcc.tar.gz
yuzu-ff442d6cf906fc4f30a99d8ccaa7e16c742cabcc.tar.xz
yuzu-ff442d6cf906fc4f30a99d8ccaa7e16c742cabcc.zip
chunk_file: General cleanup
- Remove unnecessary ifdefs - Remove commented out code. Can be retrieved later if needed.
-rw-r--r--src/common/chunk_file.h244
1 files changed, 0 insertions, 244 deletions
diff --git a/src/common/chunk_file.h b/src/common/chunk_file.h
index 7a3b537c7..dc8ac1fd9 100644
--- a/src/common/chunk_file.h
+++ b/src/common/chunk_file.h
@@ -32,35 +32,10 @@
32#include <string> 32#include <string>
33#include <list> 33#include <list>
34#include <set> 34#include <set>
35#ifndef __SYMBIAN32__
36#if defined(IOS) || defined(MACGNUSTD)
37#include <tr1/type_traits>
38#else
39#include <type_traits> 35#include <type_traits>
40#endif
41#endif
42 36
43#include "common/common.h" 37#include "common/common.h"
44#include "common/file_util.h" 38#include "common/file_util.h"
45//#include "../ext/snappy/snappy-c.h"
46
47#if defined(IOS) || defined(MACGNUSTD)
48namespace std {
49 using tr1::is_pointer;
50}
51#endif
52#ifdef __SYMBIAN32__
53namespace std {
54 template <bool bool_value>
55 struct bool_constant {
56 typedef bool_constant<bool_value> type;
57 static const bool value = bool_value;
58 };
59 template <bool bool_value> const bool bool_constant<bool_value>::value;
60 template <typename T> struct is_pointer : public bool_constant<false> {};
61 template <typename T> struct is_pointer<T*> : public bool_constant<true> {};
62}
63#endif
64 39
65template <class T> 40template <class T>
66struct LinkedListItem : public T 41struct LinkedListItem : public T
@@ -651,222 +626,3 @@ inline PointerWrapSection::~PointerWrapSection() {
651 p_.DoMarker(title_); 626 p_.DoMarker(title_);
652 } 627 }
653} 628}
654
655
656// Commented out because it is currently unused, and breaks builds on OSX
657/*class CChunkFileReader
658{
659public:
660 enum Error {
661 ERROR_NONE,
662 ERROR_BAD_FILE,
663 ERROR_BROKEN_STATE,
664 };
665
666 // Load file template
667 template<class T>
668 static Error Load(const std::string& _rFilename, int _Revision, const char *_VersionString, T& _class, std::string* _failureReason)
669 {
670 INFO_LOG(COMMON, "ChunkReader: Loading %s" , _rFilename.c_str());
671 _failureReason->clear();
672 _failureReason->append("LoadStateWrongVersion");
673
674 if (!FileUtil::Exists(_rFilename)) {
675 _failureReason->clear();
676 _failureReason->append("LoadStateDoesntExist");
677 ERROR_LOG(COMMON, "ChunkReader: File doesn't exist");
678 return ERROR_BAD_FILE;
679 }
680
681 // Check file size
682 const u64 fileSize = FileUtil::GetSize(_rFilename);
683 static const u64 headerSize = sizeof(SChunkHeader);
684 if (fileSize < headerSize)
685 {
686 ERROR_LOG(COMMON,"ChunkReader: File too small");
687 return ERROR_BAD_FILE;
688 }
689
690 FileUtil::IOFile pFile(_rFilename, "rb");
691 if (!pFile)
692 {
693 ERROR_LOG(COMMON,"ChunkReader: Can't open file for reading");
694 return ERROR_BAD_FILE;
695 }
696
697 // read the header
698 SChunkHeader header;
699 if (!pFile.ReadArray(&header, 1))
700 {
701 ERROR_LOG(COMMON,"ChunkReader: Bad header size");
702 return ERROR_BAD_FILE;
703 }
704
705 // Check revision
706 if (header.Revision != _Revision)
707 {
708 ERROR_LOG(COMMON,"ChunkReader: Wrong file revision, got %d expected %d",
709 header.Revision, _Revision);
710 return ERROR_BAD_FILE;
711 }
712
713 if (strcmp(header.GitVersion, _VersionString) != 0)
714 {
715 WARN_LOG(COMMON, "This savestate was generated by a different version of PPSSPP, %s. It may not load properly.",
716 header.GitVersion);
717 }
718
719 // get size
720 const int sz = (int)(fileSize - headerSize);
721 if (header.ExpectedSize != sz)
722 {
723 ERROR_LOG(COMMON,"ChunkReader: Bad file size, got %d expected %d",
724 sz, header.ExpectedSize);
725 return ERROR_BAD_FILE;
726 }
727
728 // read the state
729 u8* buffer = new u8[sz];
730 if (!pFile.ReadBytes(buffer, sz))
731 {
732 ERROR_LOG(COMMON,"ChunkReader: Error reading file");
733 return ERROR_BAD_FILE;
734 }
735
736 u8 *ptr = buffer;
737 u8 *buf = buffer;
738 if (header.Compress) {
739 u8 *uncomp_buffer = new u8[header.UncompressedSize];
740 size_t uncomp_size = header.UncompressedSize;
741 snappy_uncompress((const char *)buffer, sz, (char *)uncomp_buffer, &uncomp_size);
742 if ((int)uncomp_size != header.UncompressedSize) {
743 ERROR_LOG(COMMON,"Size mismatch: file: %i calc: %i", (int)header.UncompressedSize, (int)uncomp_size);
744 }
745 ptr = uncomp_buffer;
746 buf = uncomp_buffer;
747 delete [] buffer;
748 }
749
750 PointerWrap p(&ptr, PointerWrap::MODE_READ);
751 _class.DoState(p);
752 delete[] buf;
753
754 INFO_LOG(COMMON, "ChunkReader: Done loading %s" , _rFilename.c_str());
755 if (p.error != p.ERROR_FAILURE) {
756 return ERROR_NONE;
757 } else {
758 return ERROR_BROKEN_STATE;
759 }
760 }
761
762 // Save file template
763 template<class T>
764 static Error Save(const std::string& _rFilename, int _Revision, const char *_VersionString, T& _class)
765 {
766 INFO_LOG(COMMON, "ChunkReader: Writing %s" , _rFilename.c_str());
767
768 FileUtil::IOFile pFile(_rFilename, "wb");
769 if (!pFile)
770 {
771 ERROR_LOG(COMMON,"ChunkReader: Error opening file for write");
772 return ERROR_BAD_FILE;
773 }
774
775 bool compress = true;
776
777 // Get data
778 u8 *ptr = 0;
779 PointerWrap p(&ptr, PointerWrap::MODE_MEASURE);
780 _class.DoState(p);
781 size_t const sz = (size_t)ptr;
782
783 u8 * buffer = new u8[sz];
784 ptr = &buffer[0];
785 p.SetMode(PointerWrap::MODE_WRITE);
786 _class.DoState(p);
787
788 // Create header
789 SChunkHeader header;
790 header.Compress = compress ? 1 : 0;
791 header.Revision = _Revision;
792 header.ExpectedSize = (int)sz;
793 header.UncompressedSize = (int)sz;
794 strncpy(header.GitVersion, _VersionString, 32);
795 header.GitVersion[31] = '\0';
796
797 // Write to file
798 if (compress) {
799 size_t comp_len = snappy_max_compressed_length(sz);
800 u8 *compressed_buffer = new u8[comp_len];
801 snappy_compress((const char *)buffer, sz, (char *)compressed_buffer, &comp_len);
802 delete [] buffer;
803 header.ExpectedSize = (int)comp_len;
804 if (!pFile.WriteArray(&header, 1))
805 {
806 ERROR_LOG(COMMON,"ChunkReader: Failed writing header");
807 return ERROR_BAD_FILE;
808 }
809 if (!pFile.WriteBytes(&compressed_buffer[0], comp_len)) {
810 ERROR_LOG(COMMON,"ChunkReader: Failed writing compressed data");
811 return ERROR_BAD_FILE;
812 } else {
813 INFO_LOG(COMMON, "Savestate: Compressed %i bytes into %i", (int)sz, (int)comp_len);
814 }
815 delete [] compressed_buffer;
816 } else {
817 if (!pFile.WriteArray(&header, 1))
818 {
819 ERROR_LOG(COMMON,"ChunkReader: Failed writing header");
820 return ERROR_BAD_FILE;
821 }
822 if (!pFile.WriteBytes(&buffer[0], sz))
823 {
824 ERROR_LOG(COMMON,"ChunkReader: Failed writing data");
825 return ERROR_BAD_FILE;
826 }
827 delete [] buffer;
828 }
829
830 INFO_LOG(COMMON,"ChunkReader: Done writing %s",
831 _rFilename.c_str());
832 if (p.error != p.ERROR_FAILURE) {
833 return ERROR_NONE;
834 } else {
835 return ERROR_BROKEN_STATE;
836 }
837 }
838
839 template <class T>
840 static Error Verify(T& _class)
841 {
842 u8 *ptr = 0;
843
844 // Step 1: Measure the space required.
845 PointerWrap p(&ptr, PointerWrap::MODE_MEASURE);
846 _class.DoState(p);
847 size_t const sz = (size_t)ptr;
848 std::vector<u8> buffer(sz);
849
850 // Step 2: Dump the state.
851 ptr = &buffer[0];
852 p.SetMode(PointerWrap::MODE_WRITE);
853 _class.DoState(p);
854
855 // Step 3: Verify the state.
856 ptr = &buffer[0];
857 p.SetMode(PointerWrap::MODE_VERIFY);
858 _class.DoState(p);
859
860 return ERROR_NONE;
861 }
862
863private:
864 struct SChunkHeader
865 {
866 int Revision;
867 int Compress;
868 int ExpectedSize;
869 int UncompressedSize;
870 char GitVersion[32];
871 };
872}; */