NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
[REL] Export Settings 1.0.1


Joined: 06 Jul 2009
Posts: 72
Reply with quote
Hi all..

One of the most asked about questions perhaps.. but I've finally written a script to handle it exporting PhpED settings.

It will export the 'NuSphere' registry key and copy the config dir. The script will create a 'NuSphere' directory on your Desktop and put the exported data in there for convenience. From there, it's a simple case of copying the config dir back into your new PhpED data directory, and double-clicking on the .reg file to import the registry settings. I do plan to write an import script to handle this automagically too at some point.

Update 12/12/2011 - Released 1.0.1


Code:
<?php
/**
 * NuSphere PhpED Integration script to export settings
 *
 * @author Ian.H <ian.h@digiserv.net>
 * @version $Id: export_settings.php 5 2011-12-12 08:44:36Z Ian $
 */
function recursiveCopy($src, $dest)
{
    if (is_dir($src)) {
        $dh = opendir($src);

        if (is_resource($dh)) {
            if (!is_dir($dest)) {
                mkdir($dest);
            }

            while (false !== ($file = readdir($dh))) {
                if (($file == '.') || ($file == '..')) {
                    continue;
                }

                if (is_dir($src . DIRECTORY_SEPARATOR . $file)) {
                    recursiveCopy($src . DIRECTORY_SEPARATOR . $file, $dest . DIRECTORY_SEPARATOR . $file);
                } else {
                    copy($src . DIRECTORY_SEPARATOR . $file, $dest . DIRECTORY_SEPARATOR . $file);
                }
            }
        }

        closedir($dh);
    }
}

function quotePath($path)
{
    if (false !== strpos($path, ' ')) {
        $path = '"' . $path . '"';
    }

    return $path;
}

function appendTrailingSlash($path)
{
    if (substr($path, -1) != DIRECTORY_SEPARATOR) {
        $path .= DIRECTORY_SEPARATOR;
    }

    return $path;
}

$appData = appendTrailingSlash(rtrim(`echo %APPDATA%`));
$tmpDir = appendTrailingSlash(rtrim(`echo %TEMP%`));
$desktopDir = null;
$configDir = $appData . DIRECTORY_SEPARATOR . 'NuSphere' . DIRECTORY_SEPARATOR . 'PhpED' . DIRECTORY_SEPARATOR . 'config';
$shellFoldersRegKey = "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders";
$regKey = "HKEY_CURRENT_USER\\Software\\NuSphere";

// Remove any left over reg dumps
if (file_exists(quotePath($tmpDir . 'shell_folders.reg'))) {
    unlink(quotePath($tmpDir . 'shell_folders.reg'));
}

// Export shell folders to temp file
exec('reg.exe EXPORT ' . escapeshellarg($shellFoldersRegKey) . ' ' . quotePath($tmpDir . 'shell_folders.reg'), $ret);

// Get desktop dir
$shellFolders = file(quotePath($tmpDir . 'shell_folders.reg'));
unlink(quotePath($tmpDir . 'shell_folders.reg'));

foreach ($shellFolders as $folder) {
    $folder = str_replace("\x00", '', $folder);

    if (false !== strpos($folder, '=')) {
        list($folder, $path) = explode('=', $folder);

        if ($folder == '"Desktop"') {
            $desktopDir = str_replace('"', '', trim(str_replace('\\\\', DIRECTORY_SEPARATOR, $path)));
            break;
        }
    }
}

if ((null != $desktopDir) && is_dir($desktopDir)) {
    $desktopDir = appendTrailingSlash($desktopDir);

    // Create required dirs
    if (!is_dir(quotePath($desktopDir . 'NuSphere'))) {
        mkdir(quotePath($desktopDir . 'NuSphere'));
    } else {
        echo '"' . $desktopDir . 'NuSphere" directory already exists.' . "\nPlease remove this and try again.\n";
        exit;
    }
    if (!is_dir(quotePath($desktopDir . 'NuSphere' . DIRECTORY_SEPARATOR . 'config'))) {
        mkdir(quotePath($desktopDir . 'NuSphere' . DIRECTORY_SEPARATOR . 'config'));
    }

    // Export NuSphere registry key
    exec('reg.exe EXPORT ' . escapeshellarg($regKey) . ' ' . quotePath($desktopDir . 'NuSphere' . DIRECTORY_SEPARATOR . 'NuSphere.reg'), $ret);

    // Copy 'NuSphere/PhpED/config' dir
    recursiveCopy($configDir, quotePath($desktopDir . 'NuSphere' . DIRECTORY_SEPARATOR . 'config'));

    echo "Settings exported.\n";
}
?>





Cheers..

Ian


Last edited by Ian.H on Mon Dec 12, 2011 3:54 am; edited 2 times in total
View user's profileFind all posts by Ian.HSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 7823
Reply with quote
perhaps, reg.exe is more suited for manipulating with registry from a script, no? Also, what if $desktopDir contains spaces? Shouldn't it be quoted?
Otherwise a good script!

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 06 Jul 2009
Posts: 72
Reply with quote
Hi dmitri..

dmitri wrote:
perhaps, reg.exe is more suited for manipulating with registry from a script, no? Also, what if $desktopDir contains spaces? Shouldn't it be quoted?
Otherwise a good script!



Thanks for your suggestions on this.. it's a long time since I really used the console for windows stuff (more of a Unix person when it comes to a console).. but have taken note of your points and updated the script Smile



Cheers..

Ian
View user's profileFind all posts by Ian.HSend private message
[REL] Export Settings 1.0.1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic