/* ------------------------------------------- Copyright ZKA Technologies File: Main.cxx Purpose: Main entrypoint of kernel. ------------------------------------------- */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include EXTERN Kernel::Property cKernelVersion; namespace Kernel::Detail { /// @brief Filesystem auto formatter, additional checks are also done by the class. class FilesystemInstaller final { Kernel::NewFilesystemManager* fNewFS{nullptr}; public: /// @brief wizard constructor. explicit FilesystemInstaller() { if (Kernel::FilesystemManagerInterface::GetMounted()) { // Partition is mounted, cool! Kernel::kcout << "newoskrnl: No need to create for a new NewFS (EPM) partition here...\r"; fNewFS = reinterpret_cast(Kernel::FilesystemManagerInterface::GetMounted()); } else { // Mounts a NewFS from main drive. fNewFS = new Kernel::NewFilesystemManager(); Kernel::FilesystemManagerInterface::Mount(fNewFS); } if (fNewFS->GetParser()) { constexpr auto cFolderInfo = "META-INF"; const auto cDirCount = 7; const char* cDirStr[cDirCount] = { "\\Boot\\", "\\System\\", "\\Support\\", "\\Applications\\", "\\Users\\", "\\Library\\", "\\Mount\\"}; for (Kernel::SizeT dirIndx = 0UL; dirIndx < cDirCount; ++dirIndx) { auto catalogDir = fNewFS->GetParser()->GetCatalog(cDirStr[dirIndx]); if (catalogDir) { Kernel::kcout << "newoskrnl: already exists.\r"; delete catalogDir; continue; } catalogDir = fNewFS->GetParser()->CreateCatalog(cDirStr[dirIndx], 0, kNewFSCatalogKindDir); NFS_FORK_STRUCT theFork{0}; const Kernel::Char* cSrcName = cFolderInfo; Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theFork.ForkName, Kernel::rt_string_len(cSrcName)); Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDir->Name), theFork.CatalogName, Kernel::rt_string_len(catalogDir->Name)); delete catalogDir; theFork.DataSize = kNewFSForkSize; theFork.ResourceId = 0; theFork.ResourceKind = Kernel::kNewFSRsrcForkKind; theFork.Kind = Kernel::kNewFSDataForkKind; Kernel::StringView metadataFolder(kNewFSSectorSz); metadataFolder += "\r

Kind: folder

\r

Created by: system

\r

Edited by: " "system

\r

Volume Type: Zeta

\r"; metadataFolder += "

Path: "; metadataFolder += cDirStr[dirIndx]; metadataFolder += "

\r"; const Kernel::SizeT metadataSz = kNewFSSectorSz; auto catalogSystem = fNewFS->GetParser()->GetCatalog(cDirStr[dirIndx]); fNewFS->GetParser()->CreateFork(catalogSystem, theFork); fNewFS->GetParser()->WriteCatalog( catalogSystem, true, (Kernel::VoidPtr)(metadataFolder.CData()), metadataSz, cFolderInfo); delete catalogSystem; } } NFS_CATALOG_STRUCT* catalogDisk = this->fNewFS->GetParser()->GetCatalog("\\Mount\\NUL:"); const Kernel::Char* cSrcName = "DISK-INF"; if (catalogDisk) { delete catalogDisk; } else { catalogDisk = (NFS_CATALOG_STRUCT*)this->Leak()->CreateAlias("\\Mount\\NUL:"); Kernel::StringView diskFolder(kNewFSSectorSz); diskFolder += "

Kind: alias to NULL.

\r

Created by: system

\r

Edited " "by: " "system

\r

Volume Type: NULL.

\r"; diskFolder += "

Root: NUL"; diskFolder += "

\r"; NFS_FORK_STRUCT theDiskFork{0}; Kernel::rt_copy_memory((Kernel::VoidPtr)(cSrcName), theDiskFork.ForkName, Kernel::rt_string_len(cSrcName)); Kernel::rt_copy_memory((Kernel::VoidPtr)(catalogDisk->Name), theDiskFork.CatalogName, Kernel::rt_string_len(catalogDisk->Name)); theDiskFork.DataSize = kNewFSForkSize; theDiskFork.ResourceId = 0; theDiskFork.ResourceKind = Kernel::kNewFSRsrcForkKind; theDiskFork.Kind = Kernel::kNewFSDataForkKind; fNewFS->GetParser()->CreateFork(catalogDisk, theDiskFork); fNewFS->GetParser()->WriteCatalog(catalogDisk, true, (Kernel::VoidPtr)diskFolder.CData(), kNewFSSectorSz, cSrcName); delete catalogDisk; } } ~FilesystemInstaller() = default; NEWOS_COPY_DEFAULT(FilesystemInstaller); /// @brief Grab the disk's NewFS reference. /// @return NewFilesystemManager the filesystem interface Kernel::NewFilesystemManager* Leak() { return fNewFS; } }; } // namespace Kernel::Detail /// @brief Application entrypoint. /// @param Void /// @return Void EXTERN_C Kernel::Void ke_dll_entrypoint(Kernel::Void) { CGInit(); CGDrawInRegion(CGColor(0x45, 0x00, 0x06), CG::UIAccessibilty::The().Height(), CG::UIAccessibilty::The().Width(), 0, 0); CGFini(); auto root_zka_wnd = CG::CGCreateWindow(CG::cWndFlagWindow, "ZKA Setup", "Window", 0, 0, CG::UIAccessibilty::The().Height() - 20, CG::UIAccessibilty::The().Width() - 20); root_zka_wnd->w_x = 10; root_zka_wnd->w_y = 10; root_zka_wnd->w_needs_repaint = Yes; /// Now run kernel loop, until no process are running. Kernel::Detail::FilesystemInstaller(); // automatic filesystem creation. auto root_install_wnd = CG::CGCreateWindow(CG::cWndFlagButton, "Install ZKA.", "Button", 0, 0, 128, 32); root_install_wnd->w_x = 30; root_install_wnd->w_y = 60; root_install_wnd->w_needs_repaint = Yes; CG::UI_WINDOW_STRUCT* arr[] = {root_zka_wnd, root_install_wnd}; CGDrawInRegion(CGColor(0x45, 0x00, 0x06), CG::UIAccessibilty::The().Height(), CG::UIAccessibilty::The().Width(), 0, 0); CGFini(); CG::CGDrawWindowList(arr, 2); while (Yes) { } }