diff --git a/editor-python/src/Program.py b/editor-python/src/Program.py new file mode 100644 index 0000000..1fe6c58 --- /dev/null +++ b/editor-python/src/Program.py @@ -0,0 +1,82 @@ +# Copyright (C) 2024 Michael Becker +# +# This file is part of editor-python. +# +# editor-python 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 3 of the License, or +# (at your option) any later version. +# +# editor-python 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 editor-python. If not, see . + + +from editor.ui import EditorApplication + +class Program (EditorApplication): + + def __init__(self, app_id : str): + EditorApplication.__init__(self, app_id) + + +if __name__ == '__main__': + + #p = Program("net.alcetech.UniversalEditor.python.debug") + #p.start() + + from editor.core.io import Reader + r = Reader(open('/home/beckermj/Documents/Projects/mochapowered/mocha-dotnet/mocha-common/mocha-common/output/net.alcetech.Mocha.System.mcl', 'rb')) + m = r.read_fixedstring(4) + + version = r.read_single() + flags = r.read_int32() + section_count = r.read_int32() + library_guid = r.read_guid() + + print (m) + print ("library GUID: " + str(library_guid)) + print ("%d sections" % section_count) + + sects = [ ] + guids = [ ] + + for i in range(0, section_count): + sect_name = r.read_fixedstring(16) + sect_name = sect_name.strip(' \0') + + sect_offset = r.read_int32() + sect_length = r.read_int32() + sect_decompressedLength = r.read_int32() + sect_itemcount = r.read_int32() + sects.append((sect_name, sect_offset, sect_length, sect_decompressedLength, sect_itemcount)) + print(" " + sect_name) + + for (sect_name, sect_offset, sect_length, sect_decompressedLength, sect_itemcount) in sects: + if sect_name == "GUIDTable": + r.get_stream().seek(sect_offset) + + for i in range(0, sect_itemcount): + guids.append(r.read_guid()) + + elif sect_name == "Relationships": + r.get_stream().seek(sect_offset) + + for i in range(0, sect_itemcount): + + srci = r.read_int32() + reli = r.read_int32() + tgti = r.read_int32() + + srcg = guids[srci] + relg = guids[reli] + tgtg = guids[tgti] + + if str(srcg) == '{30fb6ba6-2bbb-41d2-b91a-709c00a07790}': + + print ("%s : %s = %s" % (srcg, relg, tgtg)) + diff --git a/editor-python/src/editor/core/DataFormat.py b/editor-python/src/editor/core/DataFormat.py new file mode 100644 index 0000000..e8aa710 --- /dev/null +++ b/editor-python/src/editor/core/DataFormat.py @@ -0,0 +1,20 @@ +# Copyright (C) 2024 Michael Becker +# +# This file is part of editor-python. +# +# editor-python 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 3 of the License, or +# (at your option) any later version. +# +# editor-python 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 editor-python. If not, see . + +class DataFormat: + + pass \ No newline at end of file diff --git a/editor-python/src/editor/core/ObjectModel.py b/editor-python/src/editor/core/ObjectModel.py new file mode 100644 index 0000000..d89c0b2 --- /dev/null +++ b/editor-python/src/editor/core/ObjectModel.py @@ -0,0 +1,20 @@ +# Copyright (C) 2024 Michael Becker +# +# This file is part of editor-python. +# +# editor-python 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 3 of the License, or +# (at your option) any later version. +# +# editor-python 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 editor-python. If not, see . + +class ObjectModel: + + pass \ No newline at end of file diff --git a/editor-python/src/editor/core/io/Encoding.py b/editor-python/src/editor/core/io/Encoding.py new file mode 100644 index 0000000..30e8008 --- /dev/null +++ b/editor-python/src/editor/core/io/Encoding.py @@ -0,0 +1,26 @@ +# Copyright (C) 2024 Michael Becker +# +# This file is part of editor-python. +# +# editor-python 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 3 of the License, or +# (at your option) any later version. +# +# editor-python 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 editor-python. If not, see . + +class Encoding: + + def __init__(self, value : str): + self._value = value + + def get_value() -> str: + return self._value + +Encoding.UTF8 = Encoding('utf-8') diff --git a/editor-python/src/editor/core/io/Endianness.py b/editor-python/src/editor/core/io/Endianness.py new file mode 100644 index 0000000..ac45c5c --- /dev/null +++ b/editor-python/src/editor/core/io/Endianness.py @@ -0,0 +1,25 @@ +# Copyright (C) 2024 Michael Becker +# +# This file is part of editor-python. +# +# editor-python 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 3 of the License, or +# (at your option) any later version. +# +# editor-python 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 editor-python. If not, see . + +class Endianness: + + def __init__(self, value): + self._value = value + + +Endianness.LITTLE = Endianness('little') +Endianness.BIG = Endianness('big') \ No newline at end of file diff --git a/editor-python/src/editor/core/io/Reader.py b/editor-python/src/editor/core/io/Reader.py new file mode 100644 index 0000000..495c969 --- /dev/null +++ b/editor-python/src/editor/core/io/Reader.py @@ -0,0 +1,68 @@ +# Copyright (C) 2024 Michael Becker +# +# This file is part of editor-python. +# +# editor-python 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 3 of the License, or +# (at your option) any later version. +# +# editor-python 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 editor-python. If not, see . + +from io import FileIO +import struct + +from .ReaderWriterBase import ReaderWriterBase +from .Encoding import Encoding +from .Endianness import Endianness + +from framework import Guid + +class Reader (ReaderWriterBase): + + def __init__(self, stream : FileIO): + ReaderWriterBase.__init__(self) + self._stream = stream + + def get_stream(self) -> FileIO: + return self._stream + + def read_fixedstring(self, length : int, encoding : Encoding = None) -> str: + data = self._stream.read(length) + enc = 'utf-8' if encoding is None else encoding.get_value() + return bytes.decode(data, enc) + + def read_single(self) -> float: + + data = self._stream.read(4) + + if self.get_endianness() == Endianness.LITTLE: + return struct.unpack('f', data)[0] + + raise NotImplementedError + + def read_int32(self) -> int: + + data = self._stream.read(4) + + if self.get_endianness() == Endianness.LITTLE: + return struct.unpack('i', data)[0] + + raise NotImplementedError + + def read_guid(self) -> Guid: + + data = self._stream.read(16) + + value = Guid.from_bytes(data) + return value \ No newline at end of file diff --git a/editor-python/src/editor/core/io/ReaderWriterBase.py b/editor-python/src/editor/core/io/ReaderWriterBase.py new file mode 100644 index 0000000..660ebc2 --- /dev/null +++ b/editor-python/src/editor/core/io/ReaderWriterBase.py @@ -0,0 +1,29 @@ +# Copyright (C) 2024 Michael Becker +# +# This file is part of editor-python. +# +# editor-python 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 3 of the License, or +# (at your option) any later version. +# +# editor-python 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 editor-python. If not, see . + +from .Endianness import Endianness + +class ReaderWriterBase: + + def __init__(self) -> None: + self._endianness = Endianness.LITTLE + + def get_endianness(self) -> Endianness: + return self._endianness + + def set_endianness(self, endianness : Endianness): + self._endianness = endianness \ No newline at end of file diff --git a/editor-python/src/editor/core/io/__init__.py b/editor-python/src/editor/core/io/__init__.py new file mode 100644 index 0000000..4aa66b2 --- /dev/null +++ b/editor-python/src/editor/core/io/__init__.py @@ -0,0 +1,20 @@ +# Copyright (C) 2024 Michael Becker +# +# This file is part of editor-python. +# +# editor-python 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 3 of the License, or +# (at your option) any later version. +# +# editor-python 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 editor-python. If not, see . + +from .Endianness import Endianness +from .ReaderWriterBase import ReaderWriterBase +from .Reader import Reader \ No newline at end of file diff --git a/editor-python/src/editor/ui/EditorApplication.py b/editor-python/src/editor/ui/EditorApplication.py new file mode 100644 index 0000000..e256b0e --- /dev/null +++ b/editor-python/src/editor/ui/EditorApplication.py @@ -0,0 +1,39 @@ +# Copyright (C) 2024 Michael Becker +# +# This file is part of editor-python. +# +# editor-python 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 3 of the License, or +# (at your option) any later version. +# +# editor-python 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 editor-python. If not, see . + +from framework.desktop import DesktopApplication + +import gi +gi.require_version('Gtk', '3.0') + +from gi.repository import Gtk + +from .EditorWindow import EditorWindow + +class EditorApplication(DesktopApplication): + + def __init__(self, app_id : str): + DesktopApplication.__init__(self, app_id) + + def before_start_internal(self): + print ("ok EditorApp") + + def activate(self, args): + wnd = EditorWindow() + wnd.show() + + self.app.add_window(wnd) diff --git a/editor-python/src/editor/ui/EditorWindow.py b/editor-python/src/editor/ui/EditorWindow.py new file mode 100644 index 0000000..cadc712 --- /dev/null +++ b/editor-python/src/editor/ui/EditorWindow.py @@ -0,0 +1,26 @@ +# Copyright (C) 2024 Michael Becker +# +# This file is part of editor-python. +# +# editor-python 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 3 of the License, or +# (at your option) any later version. +# +# editor-python 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 editor-python. If not, see . + +from gi.repository import Gtk + +from framework.desktop import Window + +class EditorWindow (Window): + + def on_realize(self, data): + self.set_size_request(1000, 600) + self.set_title("Universal Editor") \ No newline at end of file diff --git a/editor-python/src/editor/ui/__init__.py b/editor-python/src/editor/ui/__init__.py new file mode 100644 index 0000000..1d1c572 --- /dev/null +++ b/editor-python/src/editor/ui/__init__.py @@ -0,0 +1,18 @@ +# Copyright (C) 2024 Michael Becker +# +# This file is part of editor-python. +# +# editor-python 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 3 of the License, or +# (at your option) any later version. +# +# editor-python 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 editor-python. If not, see . + +from .EditorApplication import EditorApplication \ No newline at end of file