fileInfo.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. ########################################################################
  2. # Wiizard - A Wii games manager
  3. # Copyright (C) 2023 CYBERDEViL
  4. #
  5. # This file is part of Wiizard.
  6. #
  7. # Wiizard is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # Wiizard is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. ########################################################################
  21. """ Constants """
  22. SOURCE_LOCAL = 1 # Game file(s) are on mounted system HDD
  23. SOURCE_PART = 2 # Game file(s) are on a WBFS partition
  24. FILE_TYPE_ISO = 1
  25. FILE_TYPE_WBFS = 2
  26. DISC_IDS = ["R", "S", "B", "E"]
  27. REGION_STRS = {
  28. "A": "All",
  29. "D": "German",
  30. "E": "USA",
  31. "F": "French",
  32. "I": "Italian",
  33. "J": "Japan",
  34. "K": "Korea",
  35. "L": "Japanese import to Europe",
  36. "M": "USA import to Europe",
  37. "N": "Japanese import to USA",
  38. "P": "Europe",
  39. "S": "Spanish",
  40. "Q": "Korea with Japanese language",
  41. "T": "Korea with English language"
  42. }
  43. class ID6:
  44. """ Get elements from a ID6 string """
  45. @staticmethod
  46. def getRegion(id6):
  47. return id6[3]
  48. @staticmethod
  49. def isValid(id6):
  50. """ Validate a id6 string """
  51. if len(id6) != 6:
  52. return False
  53. if id6[0] not in DISC_IDS:
  54. return False
  55. if id6[3] not in REGION_STRS:
  56. return False
  57. return True
  58. class GameFileInfo:
  59. """ Base class to describe a game file and it's source """
  60. def __init__(self, id6, title, sourceType, sourcePath, fileType, fileSize, source):
  61. self.__id6 = id6
  62. self.__title = title
  63. self.__sourceType = sourceType
  64. self.__sourcePath = sourcePath
  65. self.__fileType = fileType
  66. self.__fileSize = fileSize # in MiB
  67. self.__source = source # source model
  68. def equals(self, other):
  69. if other.id6 != self.id6:
  70. return False
  71. if other.title != self.title:
  72. return False
  73. if other.fileType != self.fileType:
  74. return False
  75. if other.fileSize != self.fileSize:
  76. return False
  77. if other.sourceModel != self.sourceModel:
  78. return False
  79. return True
  80. @property
  81. def id6(self):
  82. return self.__id6
  83. @property
  84. def title(self):
  85. return self.__title
  86. @property
  87. def region(self):
  88. return ID6.getRegion(self.id6)
  89. @property
  90. def fileType(self):
  91. return self.__fileType
  92. @property
  93. def fileSize(self):
  94. return self.__fileSize
  95. @property
  96. def sourceType(self):
  97. return self.__sourceType
  98. @property
  99. def sourcePath(self):
  100. return self.__sourcePath
  101. @property
  102. def sourceModel(self):
  103. return self.__source
  104. def isValid(self):
  105. return ID6.isValid(self.id6)
  106. class LocalGameFileInfo(GameFileInfo):
  107. """ For game files on local HDD """
  108. def __init__(self, id6, title, path, filename, fileType, fileSize, source):
  109. GameFileInfo.__init__(self, id6, title, SOURCE_LOCAL, path, fileType, fileSize, source)
  110. self.__filename = filename
  111. @property
  112. def filename(self):
  113. return self.__filename
  114. class PartitionGameFileInfo(GameFileInfo):
  115. """ For game files on a WBFS partition """
  116. def __init__(self, id6, title, path, slot, fileType, fileSize, source):
  117. GameFileInfo.__init__(self, id6, title, SOURCE_PART, path, fileType, fileSize, source)
  118. self.__slot = slot
  119. @property
  120. def slot(self):
  121. return self.__slot