From Wiki96
Jump to: navigation, search

This is the SCM API Reference, an API used to manipulate the current system configuration. Read more about SCM here.

Function Table

All SCM functions are contained within the w96.sysConf namespace.

Call Arguments Returns Description
loadAll None Promise<void> Loads the SCM configuration from disk. System reserved.
createRoot name:String, description:String None Creates a configuration root. System reserved.
syncAll None Promise<void> Synchronizes the current SCM configuration to disk.
syncRoot name:String Promise<void> Synchronizes changes to a configuration root to disk. This is recommended over syncAll(), if you know the specific roots you will be working on.
getIndex name:String Index Object Returns the index of the specified configuration root name.
get path: String Any Returns the value of the specified path.
set path: String, value: any None Sets the value for the specified path.
setAndSync path: String, value: any Promise<void> Same as set(), but synchronizes changes to root after set.
remove path: String Boolean Removes the specified path. Returns a boolean specifiying if the removal was successful.
removeAndSync path: String Promise<boolean> Same as remove(), but synchronizes changes to root after removal.
ls path: String List of keys Returns the keys in the specified path. If path is left empty, this will return a list of roots.

Examples

Basic CRUD

Below is a simple program demonstrating simple CRUD operations.

const { sysConf: SCM } = w96;

// Test if the key exists
// We use this conditional to set any default values
if(!SCM.get("Software/TestSoftware")) {
    // Key does not exist, set some default values
    SCM.set("Software/TestSoftware/Hello", "World");
    SCM.set("Software/TestSoftware/Number", 2);
    SCM.set("Software/TestSoftware/True", true);
    
    // Commit changes
    await SCM.syncRoot("Software");
}

// Echo back the configuration values
alert(`Hello = ${SCM.get("Software/TestSoftware/Hello")}<br>
Number = ${SCM.get("Software/TestSoftware/Number")}<br>
True = ${SCM.get("Software/TestSoftware/True")}`);

// Update the number
await SCM.setAndSync("Software/TestSoftware/Number", SCM.get("Software/TestSoftware/Number") + 1);

// Delete the boolean
if(await SCM.removeAndSync("Software/TestSoftware/True")) {
    console.log("The boolean is gone.");
} else {
    console.log("There is no boolean.");
}

Object Listing

Basic GUI program listing all the objects in the specified path.

//!wrt
const { sysConf: SCM } = w96;
const { Theme } = w96.ui;
const { ListBox } = w96.ui.components;

// Define program class.
class ListingProgramBasic extends WApplication {
    constructor() { super() }
    
    async main(argv) {
        await super.main(argv);
        // Allow path from argv
        const path = argv[1] || "";
        
        // Create application window
        const wnd = this.createWindow({
            title: "SCM Lister",
            icon: await Theme.getIconUrl("mime/executable", '16x16'),
            initialHeight: 300,
            initialWidth: 300
        }, true);
        
        // Get body and append list box
        const body = wnd.getBodyContainer();
        const listBox = new ListBox();
        
        for(let i of SCM.ls(path))
            listBox.addItem(`${i.name} : ${i.type}`, i.name);
            
        body.appendChild(listBox.getElement());
        
        // Show window
        wnd.show();
    }
}

// Execute program class
return await WApplication.execAsync(new ListingProgramBasic(), this.boxedEnv.args);