Task 525: .PDE File Format

Task 525: .PDE File Format

1. List of all the properties of this file format intrinsic to its file system

The .PDE file format is a plain text source code file used primarily for Processing sketches (or older Arduino sketches), containing code in a Java-like syntax. It has no binary structure or magic number; it is simply text. The "properties intrinsic to its file system" refer to the standard file metadata properties in the file system (e.g., from os.stat or fs.stat), as these are the inherent attributes any .PDE file has when stored on a file system. These properties are not unique to .PDE but are intrinsic to how the file is managed in the file system. The list includes:

  • File Name: The name of the file (e.g., sketch.pde).
  • File Path: The full path to the file on the file system.
  • File Size: The size of the file in bytes.
  • Creation Time: The timestamp when the file was created.
  • Modification Time: The timestamp when the file was last modified.
  • Access Time: The timestamp when the file was last accessed.
  • Permissions: The file permissions (e.g., read, write, execute for owner, group, others; mode in octal like 0644).
  • Owner UID: The user ID of the file owner.
  • Group GID: The group ID of the file.
  • Inode Number: The inode number of the file (on UNIX-like systems).
  • Number of Hard Links: The number of hard links to the file.
  • Device ID: The device ID where the file resides.

3. Ghost blog embedded html javascript that allows a user to drag n drop a file of format .PDE and it will dump to screen all these properties

PDE File Properties Dumper

Drag and Drop .PDE File

Drop .PDE file here

  

4. Python class that can open any file of format .PDE and decode read and write and print to console all the properties from the above list

import os
import time

class PdeFileHandler:
    def __init__(self, filepath):
        self.filepath = filepath
        self.properties = self.get_properties()

    def get_properties(self):
        stat = os.stat(self.filepath)
        properties = {
            'File Name': os.path.basename(self.filepath),
            'File Path': os.path.abspath(self.filepath),
            'File Size': stat.st_size,
            'Creation Time': time.ctime(stat.st_ctime),
            'Modification Time': time.ctime(stat.st_mtime),
            'Access Time': time.ctime(stat.st_atime),
            'Permissions': oct(stat.st_mode)[-3:],
            'Owner UID': stat.st_uid,
            'Group GID': stat.st_gid,
            'Inode Number': stat.st_ino,
            'Number of Hard Links': stat.st_nlink,
            'Device ID': stat.st_dev
        }
        return properties

    def print_properties(self):
        for key, value in self.properties.items():
            print(f"{key}: {value}")

    def read_content(self):
        with open(self.filepath, 'r', encoding='utf-8') as f:
            return f.read()

    def write_content(self, content):
        with open(self.filepath, 'w', encoding='utf-8') as f:
            f.write(content)

# Example usage
# handler = PdeFileHandler('example.pde')
# handler.print_properties()
# content = handler.read_content()
# handler.write_content('void setup() {}')  # Example write

5. Java class that can open any file of format .PDE and decode read and write and print to console all the properties from the above list

import java.io.*;
import java.nio.file.*;
import java.nio.file.attribute.*;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class PdeFileHandler {
    private Path filepath;
    private BasicFileAttributes attrs;

    public PdeFileHandler(String filepath) throws IOException {
        this.filepath = Paths.get(filepath);
        this.attrs = Files.readAttributes(this.filepath, BasicFileAttributes.class);
    }

    public void printProperties() throws IOException {
        UserPrincipal owner = Files.getOwner(filepath);
        PosixFileAttributes posixAttrs = Files.readAttributes(filepath, PosixFileAttributes.class);
        System.out.println("File Name: " + filepath.getFileName());
        System.out.println("File Path: " + filepath.toAbsolutePath());
        System.out.println("File Size: " + attrs.size());
        System.out.println("Creation Time: " + formatTime(attrs.creationTime()));
        System.out.println("Modification Time: " + formatTime(attrs.lastModifiedTime()));
        System.out.println("Access Time: " + formatTime(attrs.lastAccessTime()));
        System.out.println("Permissions: " + posixAttrs.permissions());
        System.out.println("Owner UID: " + owner.getName());  // UID not directly available, using name
        System.out.println("Group GID: " + posixAttrs.group().getName());  // GID not directly available, using name
        System.out.println("Inode Number: " + attrs.fileKey());
        System.out.println("Number of Hard Links: " + posixAttrs.size());  // Not direct, approximate
        System.out.println("Device ID: " + attrs.fileKey());
    }

    private String formatTime(FileTime time) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
        return formatter.format(Instant.ofEpochMilli(time.toMillis()));
    }

    public String readContent() throws IOException {
        return Files.readString(filepath);
    }

    public void writeContent(String content) throws IOException {
        Files.writeString(filepath, content);
    }

    // Example usage
    // public static void main(String[] args) throws IOException {
    //     PdeFileHandler handler = new PdeFileHandler("example.pde");
    //     handler.printProperties();
    //     String content = handler.readContent();
    //     handler.writeContent("void setup() {}");
    // }
}

6. Javascript class that can open any file of format .PDE and decode read and write and print to console all the properties from the above list

const fs = require('fs');
const path = require('path');

class PdeFileHandler {
  constructor(filepath) {
    this.filepath = filepath;
    this.properties = this.getProperties();
  }

  getProperties() {
    const stat = fs.statSync(this.filepath);
    return {
      'File Name': path.basename(this.filepath),
      'File Path': path.resolve(this.filepath),
      'File Size': stat.size,
      'Creation Time': stat.birthtime.toLocaleString(),
      'Modification Time': stat.mtime.toLocaleString(),
      'Access Time': stat.atime.toLocaleString(),
      'Permissions': (stat.mode & 0o777).toString(8),
      'Owner UID': stat.uid,
      'Group GID': stat.gid,
      'Inode Number': stat.ino,
      'Number of Hard Links': stat.nlink,
      'Device ID': stat.dev
    };
  }

  printProperties() {
    for (const [key, value] of Object.entries(this.properties)) {
      console.log(`${key}: ${value}`);
    }
  }

  readContent() {
    return fs.readFileSync(this.filepath, 'utf-8');
  }

  writeContent(content) {
    fs.writeFileSync(this.filepath, content, 'utf-8');
  }
}

// Example usage
// const handler = new PdeFileHandler('example.pde');
// handler.printProperties();
// const content = handler.readContent();
// handler.writeContent('void setup() {}');

7. C class that can open any file of format .PDE and decode read and write and print to console all the properties from the above list

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
#include <unistd.h>

class PdeFileHandler {
public:
    char* filepath;
    struct stat fileStat;

    PdeFileHandler(const char* fp) {
        filepath = strdup(fp);
        if (stat(filepath, &fileStat) != 0) {
            perror("stat failed");
            exit(1);
        }
    }

    ~PdeFileHandler() {
        free(filepath);
    }

    void printProperties() {
        printf("File Name: %s\n", strrchr(filepath, '/') ? strrchr(filepath, '/') + 1 : filepath);
        printf("File Path: %s\n", filepath);
        printf("File Size: %ld bytes\n", fileStat.st_size);
        printf("Creation Time: %s", ctime(&fileStat.st_ctime));
        printf("Modification Time: %s", ctime(&fileStat.st_mtime));
        printf("Access Time: %s", ctime(&fileStat.st_atime));
        printf("Permissions: %o\n", fileStat.st_mode & 0777);
        printf("Owner UID: %d\n", fileStat.st_uid);
        printf("Group GID: %d\n", fileStat.st_gid);
        printf("Inode Number: %ld\n", fileStat.st_ino);
        printf("Number of Hard Links: %ld\n", fileStat.st_nlink);
        printf("Device ID: %ld\n", fileStat.st_dev);
    }

    char* readContent() {
        FILE* file = fopen(filepath, "r");
        if (!file) {
            perror("fopen failed");
            return NULL;
        }
        fseek(file, 0, SEEK_END);
        long size = ftell(file);
        fseek(file, 0, SEEK_SET);
        char* content = (char*)malloc(size + 1);
        fread(content, 1, size, file);
        content[size] = '\0';
        fclose(file);
        return content;
    }

    void writeContent(const char* content) {
        FILE* file = fopen(filepath, "w");
        if (!file) {
            perror("fopen failed");
            return;
        }
        fprintf(file, "%s", content);
        fclose(file);
    }
};

// Example usage
// int main() {
//     PdeFileHandler handler("example.pde");
//     handler.printProperties();
//     char* content = handler.readContent();
//     if (content) {
//         handler.writeContent("void setup() {}");
//         free(content);
//     }
//     return 0;
// }