cPy.cIO module#
- class cFileDisk[source]#
Bases:
objectClass for direct disk file Input/Output operations.This class wraps standard C file operations (fopen, fread, fwrite)
to provide a convenient interface for reading and writing files directly to disk.
- class cFile[source]#
Bases:
objectClass representing an in-memory file or data buffer.Allows reading and writing various data types to a memory block similarly to a file stream.
Handles endianness swapping if configured.
- Copy(Src: any, Size: int, FilePn: str = None)[source]#
- Copies data from a raw pointer into the internal buffer.
- SeekEnd(Offset: int) int[source]#
- Moves the data position pointer relative to the end of the data.
- Parameters:
Offset (int) – The offset in bytes (usually negative or zero).
- Returns:
The new absolute position.
- Return type:
int
- SetPos(Pos: int) int[source]#
- Sets the data position pointer to an absolute value.
- Parameters:
Pos (int) – The new position.
- Returns:
The actual new position (clamped to valid range).
- Return type:
int
- SetPosMutable(Pos: int) int[source]#
- Sets the data position pointer, enlarging the file with zeros if “Pos” lies after EOF.
- Parameters:
Pos (int) – The new position.
- Returns:
The new position.
- Return type:
int
- ReadBytes(To: any, MaxSize: int) int[source]#
- Reads raw bytes from the buffer.
Warning: only bytes reading / writing are endian independent.
- Parameters:
To – Destination buffer.
MaxSize (int) – Maximum bytes to read.
- Returns:
The number of bytes actually read.
- Return type:
int
- ReplaceBytes(Fm: any, MaxSize: int) int[source]#
- Replaces existing bytes at the current position without inserting new space.
- class cImageCodec[source]#
Bases:
objectAbstract base class for image decoding and encoding.Implement this interface to add support for new image formats.
- CheckMagic(Magic: int, ext: str) int[source]#
- Checks if the file magic number matches this codec.
- Parameters:
Magic (int) – The magic number (usually the first 4 bytes of the file).
ext (str) – The file extension.
- Returns:
1 if magic is correct, 0 if incorrect, -1 if this format has no magic number.
- Return type:
int
- class cIO[source]#
Bases:
objectMain Input/Output utility class.Provides static methods for file manipulation, path handling, ZIP archives,
system dialogs, and image loading/saving.- static AddSourceZip(ZipFilePn: str, DataFolderWithinZip: str = None)[source]#
- Mounts a ZIP file as a data source.
- Parameters:
ZipFilePn (str) – Path to the zip file.
DataFolderWithinZip (str) – Optional subfolder within the zip to treat as root.
- static SearchZipSources(DataFolderWithinZip: str = None)[source]#
- Searches for ZIP files to add as sources.
- Parameters:
DataFolderWithinZip (str) – Optional subfolder check.
- static ZipInflateRaw(SrcCompressed: any, CompressedSize: int, ToMemory: cFile) bool[source]#
- Inflates a raw deflated chunk into memory.
- Parameters:
SrcCompressed – Pointer to compressed data.
CompressedSize (int) – Size of compressed data.
ToMemory (cFile) – Destination file buffer.
- Returns:
true if successful.
- Return type:
bool
- static LoadFile(FilePn: str, To: cFile, ShowWarning: bool = True) bool[source]#
- Loads a file into memory.
- static SaveFile(FilePn: str, Src: cFile, Append: bool = False, ShowWarning: bool = True) bool[source]#
- Saves a cFile object to disk.
- static SetFileDialogInitialFolder(PrefKey: str, Folder: str)[source]#
- Sets the initial folder for a specific preference key (can be absolute or relative).
- static GetFileDialogInitialFolder(PrefKey: str) cStr[source]#
- Returns the initial folder for the given key. Returns “GetDefaultSourceFolder” if key is new.
- static GetFileDialogPrefExists(PrefKey: str) bool[source]#
- Returns false if there is no custom initial folder stored for this PrefKey.
- static SelectFolderDialog(Title: str, SelectedFolder: cStr, InitialFolder: str = None) bool[source]#
- Opens a dialog to select a folder.
- Parameters:
Title (str) – Dialog title.
SelectedFolder (cStr) – Output for selected folder path.
InitialFolder (str) – Optional start folder (absolute or relative).
- Returns:
true if a folder was selected.
- Return type:
bool
- static AddCodec(FileExtension: str, Codec: cImageCodec) bool[source]#
- Registers a new image codec for a specific extension.
- static FindImageCodec(FileExtension: str) cImageCodec[source]#
- Finds a codec responsible for the given extension.
- static SetImageDialogInitialFile(InitialFile: str)[source]#
- Sets initial file for image dialog. Overrides initial path if not nullptr.
- static SaveScreenShot(I: cImage, OptionalSuffix: str = None)[source]#
- Saves a screenshot of the given image, optionally adding a suffix.
- static GetXmlDialogInitialFile() cStr[source]#
- Returns last loaded/saved XML file or the one set via SetXmlDialogInitialFile.
- static SetModelAnimCameraBspDialogsInitialPath(InitialPath: str)[source]#
- Model, Animation, Camera, and Bsp dialogs have common initial path, because they are in the same folder
- static SetModelDialogInitialFile(InitialFile: str)[source]#
- decoding general formats for preview takes a lot of time
- static PathIsAbsolute(Path: str) bool[source]#
- Returns “true” if path is absolute local or network (contains drive letter or starts from two (back)slashes).
- static MakeRelativePath(Path: cStr) bool[source]#
- Converts the path to relative. Returns true if shortening happened successfully.
- static EnsureAbsolutePath(Path: str) cStr[source]#
- Builds an absolute path relative to the default source folder if “Path” is relative.Also ensures correct (back)slashes.
- static GetDefaultSourceFolder() cStr[source]#
- Returns folder of the first (default) source.usually program folder or its parent if running in Debug/Release.
- static SetDefaultSourceWriteFolder(WriteFolder: str)[source]#
- Defines alternative write path for source folder.
- static ReplaceReadPath(Path: cStr) bool[source]#
- Updates path to point to the write folder if applicable.Returns “true” if:1. “WriteFolder” is defined;2. “Path” lies within default source folder;3. The argument “Path” has been altered and contains absolute path including “WriteFolder”.
- static CheckReadPath(Path: str) bool[source]#
- Checks if path is within the default source folder structure.Returns “true” if:1. “WriteFolder” is defined;2. “Path” lies within default source folder.
- static GetThisFilePathName() cStr[source]#
- Returns absolute path to this executable file including its name.
- static GetDocumentsFolder() cStr[source]#
- Returns documents folder. Linux: /home/USER/Documents/, macOS: /Users/USER/Documents/, Windows: C:/Users/USER/Documents/
- static SetFilePermissions(FilePn: str)[source]#
- Corrects file attributes to ensure read/write rights.
- static CreatePath(PathOrFilePn: str, inUserDocuments: bool = True) bool[source]#
- Checks existence of all intermediate directories and creates them if necessary.
“PathOrFilePn” can be absolute / relative path or file name without path.
Examples:
- `cIO::CreatePath("1/2/3");` - Windows: `cIO::CreatePath("c:/A/B\C\File.txt")` - MacOS: `cIO::CreatePath("/A/B\C")`- Parameters:
PathOrFilePn (str) – The path to create.
inUserDocuments (bool) – If true, tries to create in user documents folder.
- Returns:
“true” if all intermediate directories exist or have been created.
- Return type:
bool
- static Exec(FilePn: str, Args: str = None, Wait: bool = False, Hide: bool = False) bool[source]#
- Executes an external file or program.
Usage examples:
1. Document pathname:cIO::Exec(cIO::EnsureAbsolutePath("~/Scripts/Scripting.pdf"))
2. Program with absolute path and optional arguments:Windows:
cIO::Exec("C:...maya.exe", "D:...Logo.mb")Linux:
cIO::Exec("/usr/bin/env python", "-V")
3. URL with protocol:cIO::Exec("http://3d-coat.com/")
- Parameters:
FilePn (str) – Path to file, program, or URL.
Args (str) – Optional arguments.
Wait (bool) – If true, waits for process to finish.
Hide (bool) – If true, hides the window.
- Returns:
true if execution started successfully.
- Return type:
bool
- static CheckProcessInMemory(ProcName: str) bool[source]#
- Checks if a process with the given name is running.
- Parameters:
ProcName (str) – Process name (case-insensitive partial match).
- Returns:
true if process exists.
- Return type:
bool
- static Explore(Folder: str) bool[source]#
- Opens a folder in the system file explorer.Examples:
cIO::Explore("Shaders")- Parameters:
Folder (str) – Absolute or relative path.
- Returns:
true on success.
- Return type:
bool
- static CompareFileChangeTimes(FilePn0: str, FilePn1: str) bool[source]#
- Compares file modification times.
- Parameters:
FilePn0 (str) – First file path.
FilePn1 (str) – Second file path.
- Returns:
“true” when “FilePn0” is older than “FilePn1”.
- Return type:
bool
- static NeedUpdateFile(FileToUpdate: str, SourceFile: str) bool[source]#
- Returns true if FileToUpdate does not exist or is older than SourceFile.
- static CombineImages(File1: str, File2: str, FileOut: str) bool[source]#
- Combines two images into an output image with the same format.
- Returns:
true if successful.
- Return type:
bool
- static CheckDifferentDisks(PathName0: str, PathName1: str) bool[source]#
- Returns “true” when files/folders “PathName0” and “PathName1” reside on different disks.Note: paths could be non-existent.
- static RemoveFolder(Folder: str, Recursive: bool = True) bool[source]#
- Removes a directory.
- Parameters:
Folder (str) – Directory path.
Recursive (bool) – If true, deletes content recursively.
- static GetDiskFreeSpace() float[source]#
- Returns number of free megabytes on the disk containing this program.
- static FileExists(filename: str) bool[source]#
- Returns true if file exists.
- Parameters:
filename (str) – The filename. Relative and absolute paths are supported. Documents folder placement taken into account. Checked in both install and documents folders.
- Returns:
true if file exists.
- Return type:
bool
- static FileCopy(Src: str, Dst: str, overwrite: bool = True) bool[source]#
- Copy file from Src to Dst.
- Parameters:
Src (str) – The source file.
Dst (str) – The destination file. If file is in install folder, it will be copied to the documents folder.
overwrite (bool) – If true, overwrites existing file.
- Returns:
true if file copied successfully.
- Return type:
bool
- static GetDiskSerialNumber() cStr[source]#
- Returns serial number of bootable hard disk.Examples: MacOS “6RY57LG3”, Windows “1490395c”, Linux “49cb4cde”.
- Returns:
Serial number or empty string on failure.
- Return type:
- static GetMACAddress() cStr[source]#
- Returns primary MAC address.Format: “xx:xx:xx:xx:xx:xx”.
- Returns:
MAC address or empty string on failure.
- Return type: