예제 #1
0
파일: ps2save.py 프로젝트: Jay-Jay-OPL/mymc
	def save_max_drive(self, f):
		if lzari == None:
			raise error, ("The lzari module is needed to "
				      " decompress MAX Drive saves.")
		iconsysname = ""
		icon_sys = self.get_icon_sys()
		if icon_sys != None:
			title = icon_sys_title(icon_sys, "ascii")
			if len(title[0]) > 0 and title[0][-1] != ' ':
				iconsysname = title[0] + " " + title[1].strip()
			else:
				iconsysname = title[0] + title[1].rstrip()
		s = ""
		dirent = self.dirent
		for i in range(dirent[2]):
			(ent, data) = self.get_file(i)
			if not mode_is_file(ent[0]):
				raise error, "Non-file in save file."
			s += struct.pack("<L32s", ent[2], ent[8])
			s += data
			s += "\0" * (round_up(len(s) + 8, 16) - 8 - len(s))
		length = len(s)
		progress =  "compressing " + dirent[8] + ": "
		compressed = lzari.encode(s, progress)
		hdr = struct.pack("<12sL32s32sLLL", PS2SAVE_MAX_MAGIC,
				  0, dirent[8], iconsysname,
				  len(compressed) + 4, dirent[2], length)
		crc = binascii.crc32(hdr)
		crc = binascii.crc32(compressed, crc)
		f.write(struct.pack("<12sL32s32sLLL", PS2SAVE_MAX_MAGIC,
				    crc & 0xFFFFFFFF, dirent[8], iconsysname,
				    len(compressed) + 4, dirent[2], length))
		f.write(compressed)
		f.flush()
예제 #2
0
파일: ps2save.py 프로젝트: Jay-Jay-OPL/mymc
	def load_ems(self, f):
		"""Load EMS (.psu) save files."""
		
		cluster_size = 1024

		dirent = unpack_dirent(_read_fixed(f, PS2MC_DIRENT_LENGTH))
		dotent = unpack_dirent(_read_fixed(f, PS2MC_DIRENT_LENGTH))
		dotdotent = unpack_dirent(_read_fixed(f, PS2MC_DIRENT_LENGTH))
		if (not mode_is_dir(dirent[0])
		    or not mode_is_dir(dotent[0])
		    or not mode_is_dir(dotdotent[0])
		    or dirent[2] < 2):
			raise corrupt, ("Not a EMS (.psu) save file.", f)

		dirent[2] -= 2
		self.set_directory(dirent)

		for i in range(dirent[2]):
			ent = unpack_dirent(_read_fixed(f,
							PS2MC_DIRENT_LENGTH))
			if not mode_is_file(ent[0]):
				raise subdir, f
			flen = ent[2]
			self.set_file(i, ent, _read_fixed(f, flen))
			_read_fixed(f, round_up(flen, cluster_size) - flen)
예제 #3
0
파일: ps2save.py 프로젝트: Jay-Jay-OPL/mymc
	def _load_max_drive_2(self):
		(length, s) = self._compressed
		self._compressed = None
		
		if lzari == None:
			raise error, ("The lzari module is needed to "
				      " decompress MAX Drive saves.")
		s = lzari.decode(s, length,
				 "decompressing " + self.dirent[8] + ": ")
		dirlen = self.dirent[2]
		now = tod_now()
		off = 0
		for i in range(dirlen):
			if len(s) - off < 36:
				raise eof, f
			(l, name) = struct.unpack("<L32s", s[off : off + 36])
			name = zero_terminate(name)
			# print "%08x %08x %s" % (off, l, name)
			off += 36
			data = s[off : off + l]
			if len(data) != l:
				raise eof, f
			self.set_file(i,
				      (DF_RWX | DF_FILE | DF_0400, 0, l,
				       now, 0, 0, now, 0, name),
				      data)
			off += l
			off = round_up(off + 8, 16) - 8
예제 #4
0
파일: ps2save.py 프로젝트: Ben0mega/mymc
 def save_max_drive(self, f):
     if lzari == None:
         raise error, ("The lzari module is needed to "
                       " decompress MAX Drive saves.")
     iconsysname = ""
     icon_sys = self.get_icon_sys()
     if icon_sys != None:
         title = icon_sys_title(icon_sys, "ascii")
         if len(title[0]) > 0 and title[0][-1] != ' ':
             iconsysname = title[0] + " " + title[1].strip()
         else:
             iconsysname = title[0] + title[1].rstrip()
     s = ""
     dirent = self.dirent
     for i in range(dirent[2]):
         (ent, data) = self.get_file(i)
         if not mode_is_file(ent[0]):
             raise error, "Non-file in save file."
         s += struct.pack("<L32s", ent[2], ent[8])
         s += data
         s += "\0" * (round_up(len(s) + 8, 16) - 8 - len(s))
     length = len(s)
     progress = "compressing " + dirent[8] + ": "
     compressed = lzari.encode(s, progress)
     hdr = struct.pack("<12sL32s32sLLL", PS2SAVE_MAX_MAGIC, 0, dirent[8],
                       iconsysname,
                       len(compressed) + 4, dirent[2], length)
     crc = binascii.crc32(hdr)
     crc = binascii.crc32(compressed, crc)
     f.write(
         struct.pack("<12sL32s32sLLL", PS2SAVE_MAX_MAGIC, crc & 0xFFFFFFFF,
                     dirent[8], iconsysname,
                     len(compressed) + 4, dirent[2], length))
     f.write(compressed)
     f.flush()
예제 #5
0
파일: ps2save.py 프로젝트: Ben0mega/mymc
    def _load_max_drive_2(self):
        (length, s) = self._compressed
        self._compressed = None

        if lzari == None:
            raise error, ("The lzari module is needed to "
                          " decompress MAX Drive saves.")
        s = lzari.decode(s, length, "decompressing " + self.dirent[8] + ": ")
        dirlen = self.dirent[2]
        timestamp = self.dirent[3]
        off = 0
        for i in range(dirlen):
            if len(s) - off < 36:
                raise eof, f
            (l, name) = struct.unpack("<L32s", s[off:off + 36])
            name = zero_terminate(name)
            # print "%08x %08x %s" % (off, l, name)
            off += 36
            data = s[off:off + l]
            if len(data) != l:
                raise eof, f
            self.set_file(i, (DF_RWX | DF_FILE | DF_0400 | DF_EXISTS, 0, l,
                              timestamp, 0, 0, timestamp, 0, name), data)
            off += l
            off = round_up(off + 8, 16) - 8
예제 #6
0
    def save_ems(self, f):
        cluster_size = 1024

        dirent = self.dirent[:]
        dirent[2] += 2
        f.write(pack_dirent(dirent))
        f.write(
            pack_dirent((DF_RWX | DF_DIR | DF_0400 | DF_EXISTS, 0, 0,
                         dirent[3], 0, 0, dirent[3], 0, ".")))
        f.write(
            pack_dirent((DF_RWX | DF_DIR | DF_0400 | DF_EXISTS, 0, 0,
                         dirent[3], 0, 0, dirent[3], 0, "..")))

        for i in range(dirent[2] - 2):
            (ent, data) = self.get_file(i)
            f.write(pack_dirent(ent))
            if not mode_is_file(ent[0]):
                raise error, "Directory has a subdirectory."
            f.write(data)
            f.write("\0" * (round_up(len(data), cluster_size) - len(data)))
        f.flush()
예제 #7
0
파일: ps2save.py 프로젝트: Jay-Jay-OPL/mymc
	def save_ems(self, f):
		cluster_size = 1024

		dirent = self.dirent[:]
		dirent[2] += 2
		f.write(pack_dirent(dirent))
		f.write(pack_dirent((DF_RWX | DF_DIR | DF_0400 | DF_EXISTS,
				     0, 0, dirent[3],
				     0, 0, dirent[3], 0, ".")))
		f.write(pack_dirent((DF_RWX | DF_DIR | DF_0400 | DF_EXISTS,
				     0, 0, dirent[3],
				     0, 0, dirent[3], 0, "..")))
				     
		for i in range(dirent[2] - 2):
			(ent, data) = self.get_file(i)
			f.write(pack_dirent(ent))
			if not mode_is_file(ent[0]):
				raise error, "Directory has a subdirectory."
			f.write(data)
			f.write("\0" * (round_up(len(data), cluster_size)
					- len(data)))
		f.flush()
예제 #8
0
파일: ps2save.py 프로젝트: Ben0mega/mymc
    def load_ems(self, f):
        """Load EMS (.psu) save files."""

        cluster_size = 1024

        dirent = unpack_dirent(_read_fixed(f, PS2MC_DIRENT_LENGTH))
        dotent = unpack_dirent(_read_fixed(f, PS2MC_DIRENT_LENGTH))
        dotdotent = unpack_dirent(_read_fixed(f, PS2MC_DIRENT_LENGTH))
        if (not mode_is_dir(dirent[0]) or not mode_is_dir(dotent[0])
                or not mode_is_dir(dotdotent[0]) or dirent[2] < 2):
            raise corrupt, ("Not a EMS (.psu) save file.", f)

        dirent[2] -= 2
        self.set_directory(dirent)

        for i in range(dirent[2]):
            ent = unpack_dirent(_read_fixed(f, PS2MC_DIRENT_LENGTH))
            if not mode_is_file(ent[0]):
                raise subdir, f
            flen = ent[2]
            self.set_file(i, ent, _read_fixed(f, flen))
            _read_fixed(f, round_up(flen, cluster_size) - flen)