/**********************************************************************
This script is provided as part of the Daz Script Documentation. The
contents of this script, and\or any portion thereof, may only be used
in accordance with the following license:
Creative Commons Attribution 3.0 Unported (CC BY 3.0)
- http://creativecommons.org/licenses/by/3.0
To contact Daz 3D or for more information about Daz Script visit the
Daz 3D website:
- http://www.daz3d.com
**********************************************************************/
// Source: /public/software/dazstudio/4/referenceguide/scripting/api_reference/samples/file_io/install_manager_config_import/start
// DAZ Studio version 4.7.0.12 filetype DAZ Script
// Define an anonymous function;
// serves as our main loop,
// limits the scope of variables
(function(){
var s_sToolName = "Install Manager Configuration";
var s_sScriptPath = getScriptFileName();
var s_oScriptFile = new DzFileInfo( s_sScriptPath );
// Install Manager configuration file keywords
var s_sAccount = "Account";
var s_sAccountTitle = "AccountTitle";
var s_sAllowDesktopShortcuts = "AllowDesktopShortcuts";
var s_sAllowStartMenuShortcuts = "AllowStartMenuShortcuts";
var s_sAppBitArch = "AppBitArch";
var s_sApplicationPaths = "ApplicationPaths";
var s_sAppName = "AppName";
var s_sAppPath = "AppPath";
var s_sAppVersion = "AppVersion";
var s_sAutoDelete = "AutoDelete";
var s_sAutoBackup = "AutoBackup";
var s_sAutoInstall = "AutoInstall";
var s_sAutoShowInstallModule = "AutoShowInstallModule";
var s_sBackupPath = "BackupPath";
var s_sCurInstallPath = "CurInstallPath";
var s_sCurrentTabIdx = "CurrentTabIdx";
var s_sCustomUserData = "CustomUserData";
var s_sDownloadDetailsToggled = "DownloadDetailsToggled";
var s_sDownloadDisplayHidden = "DownloadDisplayHidden";
var s_sDownloadPath = "DownloadPath";
var s_sDownloadSortIdx = "DownloadSortIdx";
var s_sGeneral = "General";
var s_sHideCurrentNotificationId = "HideCurrentNotificationId";
var s_sInstallDetailsToggled = "InstallDetailsToggled";
var s_sInstallDisplayHidden = "InstallDisplayHidden";
var s_sInstalledDetailsToggled = "InstalledDetailsToggled";
var s_sInstallSortIdx = "InstallSortIdx";
var s_sInstallPath = "InstallPath";
var s_sInstallPaths = "InstallPaths";
var s_sInstallPathTitle = "InstallPathTitle";
var s_sInstalledSortIdx = "InstalledSortIdx";
var s_sMarkInstalledContentAsNew = "MarkInstalledContentAsNew";
var s_sMaxConnections = "MaxConnections";
var s_sOverrideColorScheme = "OverrideColorScheme";
var s_sOverrideManifestDir = "OverrideManifestDir";
var s_sOverrideThumbnailDir = "OverrideThumbnailDir";
var s_sOverrideThumbnailMaxHeight = "OverrideThumbnailMaxHeight";
var s_sRememberPassword = "RememberPassword";
var s_sServerSideThumbnailResize = "ServerSideThumbnailResize";
var s_sShowDateColumn = "ShowDateColumn";
var s_sShowItemThumbnails = "ShowItemThumbnails";
var s_sShowLaunchOpen = "ShowLaunchOpen";
var s_sShowMetadataColumn = "ShowMetadataColumn";
var s_sShowReadMeColumn = "ShowReadMeColumn";
var s_sShowProductInfo = "ShowProductInfo";
var s_sShowSizeColumn = "ShowSizeColumn";
var s_sShowTips = "ShowTips";
var s_sSize = "size";
var s_sSoftware32Path = "Software32Path";
var s_sSoftware64Path = "Software64Path";
var s_sTagID = "TagID";
var s_sTags = "Tags";
var s_sTagValue = "TagValue";
var s_sUpdatesToPrevious = "UpdatesToPrevious";
// Local keywords
var s_sItems = "items";
// Keyword collections
var s_aMultiPartSectionNames = [ s_sInstallPaths, s_sApplicationPaths, s_sTags ];
var s_aValidSectionNames = [].concat( s_sGeneral, s_aMultiPartSectionNames, s_sCustomUserData );
var s_aGeneralKeyNames = [
s_sAccount, s_sAccountTitle, s_sAllowDesktopShortcuts, s_sAllowStartMenuShortcuts,
s_sAutoDelete, s_sAutoInstall, s_sAutoShowInstallModule, s_sCurInstallPath, s_sCurrentTabIdx,
s_sDownloadDetailsToggled, s_sDownloadDisplayHidden, s_sDownloadPath, s_sDownloadSortIdx,
s_sHideCurrentNotificationId, s_sInstallDetailsToggled, s_sInstallDisplayHidden, s_sInstalledDetailsToggled,
s_sInstallSortIdx, s_sInstalledSortIdx, s_sMarkInstalledContentAsNew, s_sMaxConnections, s_sOverrideManifestDir,
s_sOverrideThumbnailDir, s_sOverrideThumbnailMaxHeight, s_sRememberPassword,
s_sShowDateColumn, s_sShowItemThumbnails, s_sShowLaunchOpen, s_sShowMetadataColumn, s_sShowReadMeColumn,
s_sShowProductInfo, s_sShowSizeColumn, s_sShowTips, s_sSoftware32Path, s_sSoftware64Path, s_sUpdatesToPrevious
];
var s_aExperimentalKeyNames = [ s_sAutoBackup, s_sBackupPath, s_sOverrideColorScheme, s_sServerSideThumbnailResize ];
var s_aInstallPathsKeyNames = [ s_sInstallPathTitle, s_sInstallPath ];
var s_aApplicationPathsKeyNames = [ s_sAppName, s_sAppVersion, s_sAppBitArch, s_sAppPath ];
var s_aTagsKeyNames = [ s_sTagID, s_sTagValue ];
var s_aMultiPartKeyNames = [].concat( s_sSize, s_aInstallPathsKeyNames, s_aApplicationPathsKeyNames, s_aTagsKeyNames );
var s_aValidKeyNames = [].concat( s_aGeneralKeyNames, s_aExperimentalKeyNames, s_aMultiPartKeyNames );
// Common strings
var s_sNativeFormats = text( "DAZ Studio Formats" );
var s_sPoserFormats = text( "Poser Formats" );
var s_sOtherFormats = text( "Other Import Formats" );
// Helpers
var s_oStringHelper = new DzStringHelper();
var s_oArrayHelper = new DzArrayHelper();
// Listview created in one function; referenced in another
var s_wLocalView = undefined;
/*********************************************************************/
// String : A function for retrieving a translation if one exists
function text( sText )
{
// If the version of the application supports qsTr()
if( typeof( qsTr ) != "undefined" ){
// Return the translated (if any) text
return qsTr( sText );
}
// Return the original text
return sText;
};
/*********************************************************************/
// void : Checks unique mapped items, unchecks non-unique, non-mapped items
function setUniqueMappedItems( wListView )
{
// Get the content manager
var oContentMgr = App.getContentMgr();
// Declare working variables
var wListViewItem;
var sType, sLabel, sPath, sLast;
var aPaths, aValue;
var bMapped;
var nPaths;
// Get all of the items from the listview
var aListItems = wListView.getItems( DzListView.All );
// Iterate over the items
for( var i = 0; i < aListItems.length; i += 1 ){
// Get the 'current' item
wListViewItem = aListItems[ i ];
// Get the label of the item
sLabel = wListViewItem.text( 0 );
// If the item is a root
if( wListViewItem.depth() == 0 ){
// Set the type to the label of the item
sType = sLabel;
// Initialize unique path variables
aPaths = [];
nPaths = aPaths.length;
// Uncheck it; if it's a controller it'll get checked
// according to the checked state of it's children
wListViewItem.on = false;
// Next!!
continue;
}
// Get the path of the item
sPath = wListViewItem.text( 2 );
// Based on the type, check whether the path is mapped
switch( sType ){
case s_sNativeFormats:
bMapped = oContentMgr.contentDirectoryIsMapped( sPath );
break;
case s_sPoserFormats:
bMapped = oContentMgr.poserDirectoryIsMapped( sPath );
break;
case s_sOtherFormats:
bMapped = oContentMgr.importDirectoryIsMapped( sPath );
break;
default:
bMapped = false;
return;
}
// If the path is mapped
if( bMapped ){
// Split the path into parts
aValue = sPath.split( "/" );
// Get the last part; lowercased for case-insensitive compares
sLast = aValue[ aValue.length - 1 ].toLowerCase();
// Lowercase the label; for case-insensitive compares
sLabel = sLabel.toLowerCase();
// If the end of the path does not match the label
if( sLast != sLabel ){
// It [tenitively] does not match the pattern used by the application
bMapped = false;
// If this is a special case
if( sLast == "content" ){
// Remove the last part
aValue.pop();
// Get the new last part; lowercase for case-insensitive compares
sLast = aValue[ aValue.length - 1 ].toLowerCase();
// If the end of the special case matches the label
if( sLast == sLabel ){
// It matches the pattern the application uses
bMapped = true;
}
}
}
// Append the path to our list, if it is not already there
aPaths = s_oArrayHelper.addToArray( aPaths, sPath );
// If the path did not already exist in the list;
// the length of the array has grown
if( aPaths.length > nPaths ){
// Check the item; i.e. it's unique
wListViewItem.on = true;
// Update our count
nPaths = aPaths.length;
// If the path already existed
} else {
// Uncheck the item; i.e. it is not unique
wListViewItem.on = false;
}
// If the path is not mapped
} else {
// Uncheck the item
wListViewItem.on = false;
}
}
};
/*********************************************************************/
// void : Checks uniquely mapped directory items, unchecks non-unique items
function setUniqueMappedDirs()
{
// If our listview is not defined
if( typeof( s_wLocalView ) == undefined ){
// We are done...
return;
}
// Check the items that are uniquely mapped
setUniqueMappedItems( s_wLocalView );
};
/*********************************************************************/
// void : Adds the mapped directories known by Install Manager
function addUniqueRemoteMappedPaths( wListView, aPathItems )
{
// If we do not have paths
if( aPathItems.length < 1 ){
// We are done
return;
}
// Declare working variables
var wPathItem, wLastItem;
var sPath;
var oPathItem;
var nChildIdx, nPathIdx;
var aPaths;
// Create the root item
var wRootItem = wListView.firstChild();
// Iterate until we no longer have a root item
while( wRootItem ){
// Adding a new item prepends it to te list, so
// we need to get the last item before we start
// adding new items so that we can move new
// items to the end of the list
// Get the first child
wLastItem = wRootItem.firstChild();
// Set the child index based on whether we have a child
nChildIdx = (wLastItem ? 1 : 0);
// Pre-size an array of mapped paths
aPaths = new Array( wRootItem.childCount() );
// Until we've reached the last child
while( nChildIdx < aPaths.length ){
// Set the value of the n'th element; offset for 0 vs 1 based
aPaths[ nChildIdx - 1 ] = wLastItem.text( 1 );
// Get the next child item
wLastItem = wLastItem.nextSibling();
// Increment the child index
nChildIdx += 1;
}
// Iterate over the mapped items, in reverse order,
// because we want the same order as they currently
// exist, and adding an item prepends to the list
for( var i = aPathItems.length; i > 0; i -= 1 ){
// Get the 'current' item; we adjust the index
// because we are iterating in reverse order
oPathItem = aPathItems[ i - 1 ];
// Get the path from the item
sPath = oPathItem[ s_sInstallPath ];
// Get the index of the path
nPathIdx = aPaths.indexOf( sPath );
// If the path is already in the list
if( nPathIdx > -1 ){
// Initialize
nChildIdx = 0;
// Get the first child
wPathItem = wRootItem.firstChild();
// While we have an item and we have not reached our path
while( wPathItem && nChildIdx != nPathIdx ){
// Increment the child count
nChildIdx += 1;
// Get the next sibling
wPathItem = wRootItem.nextSibling();
}
// If we have an item
if( wPathItem ){
// Set the source to both
wPathItem.setText( 1, "Both" );
}
// Next!!
continue;
}
// Create an item for the path
wPathItem = new DzCheckListItem( wRootItem, DzCheckListItem.CheckBox );
// Set the label
wPathItem.setText( 0, oPathItem[ s_sInstallPathTitle ] );
// Set the source
wPathItem.setText( 1, "DIM" );
// Set the path
wPathItem.setText( 2, sPath );
// If we have a last item
if( wLastItem ){
// Move the new item after it
wPathItem.moveItem( wLastItem );
}
// Update the last item to the newly added item
wLastItem = wPathItem;
}
// Get the next root item
wRootItem = wRootItem.nextSibling();
}
};
/*********************************************************************/
// void : Adds the mapped directories known by DAZ Studio as items, based on type
function addLocalMappedPaths( wListView, sType )
{
// Get the content manager
var oContentMgr = App.getContentMgr();
// Initialize the number of directories
var nDirs = -1;
// Based on type, set the number of directories
switch( sType ){
case s_sNativeFormats:
nDirs = oContentMgr.getNumContentDirectories();
break;
case s_sPoserFormats:
nDirs = oContentMgr.getNumPoserDirectories();
break;
case s_sOtherFormats:
nDirs = oContentMgr.getNumImportDirectories();
break;
default:
return;
}
// If we have directories
if( nDirs >= 0 ){
// Create the root item for the type
var wRootItem = new DzCheckListItem( wListView, DzCheckListItem.CheckBoxController );
// Set the text to the type
wRootItem.setText( 0, sType );
// Expand the item; show it's children
wRootItem.open = true;
// Declare working variables
var nDir;
var sPath;
var oFolder;
var wPathItem;
// Iterate over the directories, in reverse order,
// because we want them displayed in the same order
// as they currently exist, and adding an item
// prepends to the list
for( var i = nDirs; i > 0; i -= 1 ){
// Adjust the index because we are iterating in reverse order
nDir = (i - 1);
// Based on type, get the n'th folder
switch( sType ){
case s_sNativeFormats:
oFolder = oContentMgr.getContentDirectory( nDir );
break;
case s_sPoserFormats:
oFolder = oContentMgr.getPoserDirectory( nDir );
break;
case s_sOtherFormats:
oFolder = oContentMgr.getImportDirectory( nDir );
break;
default:
oFolder = undefined;
break;
}
// If we do not have a folder
if( !oFolder ){
// Next!!
continue;
}
// Get the full path of the folder
sPath = oFolder.fullPath;
// Create an item for the path
wPathItem = new DzCheckListItem( wRootItem, DzCheckListItem.CheckBox );
// Set the label
wPathItem.setText( 0, oFolder.label );
// Set the source
wPathItem.setText( 1, "DS" );
// Set the path
wPathItem.setText( 2, sPath );
}
}
};
/*********************************************************************/
// Object : Retrieve checked path items from a listview
function getCheckedPathItems( wListView )
{
// Define working variables
var oPaths = {};
var aPaths = [];
var sType = "";
// Declare working variables
var wItem;
var oItem;
// Get all of the items
var aCheckedItems = wListView.getItems( DzListView.All );
// Iterate over the checked items
for( var i = 0; i < aCheckedItems.length; i += 1 ){
// Get the 'current' item
wItem = aCheckedItems[ i ];
// If the item is at the root depth; i.e. it's a checkbox controller
if( wItem.depth() == 0 ){
// If we have a type
if( !sType.isEmpty() ){
// Set the paths for the type
oPaths[ sType ] = aPaths;
}
// Get the label
sType = wItem.text( 0 );
// Get the paths for the type
aPaths = oPaths[ sType ];
// If paths haven't been defined for the type yet
if( aPaths == undefined ){
// Create a new array
aPaths = [];
}
// Next!!
continue;
}
// If the item is checked
if( wItem.on ){
// Add the path to the array
aPaths = s_oArrayHelper.addToArray( aPaths, wItem.text( 2 ) );
}
// If we have a type
if( !sType.isEmpty() ){
// Set the paths for the type
oPaths[ sType ] = aPaths;
}
}
// Return the path items
return oPaths;
};
/*********************************************************************/
// Object : Prompt the user to choose directories to be mapped
function getUserMappedDirs( sAccount, aAccountMappedItems )
{
// Define common values
var sObjectNamePrefix = s_oStringHelper.stripSpaces( s_sToolName );
var sLabel = text( "Label" );
var sSource = text( "Source" );
var sPath = text( "Path" );
var sInstallManager = text( "Install Manager" );
var sContentPathShortcuts = text( "Content Path Shortcuts" );
var sRemoteTitle = String("%1 %2 :").arg( sInstallManager ).arg( sContentPathShortcuts );
var sLocalTitle = text( "%1 Mapped Directories :" ).arg( App.appName );
var sSelectCurrent = text( "Select Currently Mapped" );
// Create a basic dialog
var wDlg = new DzBasicDialog();
// Set the title
wDlg.caption = String("%1 (%2)").arg( s_sToolName ).arg( sAccount );
// Get the wrapped QWidget
var oDlg = wDlg.getWidget();
// Set the object name; used to store/retrieve unique dialog geometry
oDlg.objectName = sObjectNamePrefix;
// Create a label
var wLbl = new DzLabel( wDlg );
// Get the wrapped QWidget
var oLbl = wLbl.getWidget();
// Set the object name; used for interactive lessons and inline help
oLbl.objectName = String("%1DescriptionLbl").arg( sObjectNamePrefix );
// Set styling options on the label
wLbl.wordWrap = true;
// If the application version is 4.10.0.22 or newer
if( App.version64 >= 0x0004000a00000016 ){
// Disable eliding
wLbl.elideMode = DzWidget.ElideNone;
}
// Set the text
wLbl.text = text( "Use the list displayed below to select which paths to " +
"map within %1.
The \"What's This?\" button, in the lower left " +
"corner of this dialog, can be used to view more information about a " +
"particular widget; simply press the button, then click on the widget." +
"