Joined: 06 Jul 2009 |
Posts: 72 |
|
|
|
Posted: Fri Dec 09, 2011 7:58 am |
|
|
|
|
|
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
<?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
|
Joined: 06 Jul 2009 |
Posts: 72 |
|
|
|
Posted: Mon Dec 12, 2011 3:52 am |
|
|
|
|
|
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
Cheers..
Ian
|
|