public static void ActivateAlreadyRunningInstance(string[] args, tvProfile aoProfile) { if ( 0 == args.Length ) { // This activates a previous instance before exiting. PostMessage((IntPtr)HWND_BROADCAST, WM_SHOWME, IntPtr.Zero, IntPtr.Zero); } else { tvProfile loProfile = null; if ( null != aoProfile.sLoadedPathFile ) { loProfile = aoProfile; } else { aoProfile.bAppFullyLoaded = true; // Turns off the "loading" message. // The default profile was likely attempted but failed to load // (due to contention). Try loading the backup profile instead. string lsPath = Path.GetDirectoryName(aoProfile.sDefaultPathFile); string lsFilename = Path.GetFileName(aoProfile.sDefaultPathFile); string lsExt = Path.GetExtension(aoProfile.sDefaultPathFile); string lsBackupPathFile = Path.Combine(lsPath, lsFilename) + ".backup" + lsExt; loProfile = new tvProfile(lsBackupPathFile, tvProfileFileCreateActions.NoFileCreate); loProfile.LoadFromCommandLineArray(args, tvProfileLoadActions.Merge); } // Arguments were passed, so start a new "-RunOnce" instance. loProfile.LoadFromCommandLine("-ActivateAlreadyRunningInstance -RunOnce", tvProfileLoadActions.Merge); loProfile.bAppFullyLoaded = true; // Turns off the "loading" message. DoGoPcBackup loDoDa = new DoGoPcBackup(loProfile); loDoDa.CleanupFiles(); loDoDa.BackupFiles(); } }
private void ReplaceDefaultProfileFromCommandLine(String[] asCommandLineArray) { this.LoadFromCommandLineArray(asCommandLineArray, tvProfileLoadActions.Overwrite); String[] lsIniKeys = new String[] { "-ini", "-ProfileFile" }; int liIniKeyIndex = - 1; if ( this.ContainsKey(lsIniKeys[0]) ) { liIniKeyIndex = 0; } else if ( this.ContainsKey(lsIniKeys[1]) ) { liIniKeyIndex = 1; } String lsProfilePathFile = null; if ( -1 != liIniKeyIndex ) { lsProfilePathFile = this.sValue(lsIniKeys[liIniKeyIndex], ""); } bool lbFirstArgIsFile = false; String lsFirstArg = null; try { if ( -1 != this.sInputCommandLineArray[0].IndexOf(".vshost.") || this.sInputCommandLineArray[0] == this.sExePathFile ) { lsFirstArg = this.sInputCommandLineArray[1]; } else { lsFirstArg = this.sInputCommandLineArray[0]; } } catch {} if ( null != lsFirstArg && File.Exists(this.sRelativeToProfilePathFile(lsFirstArg)) ) { if ( null != lsProfilePathFile ) { // If the first argument passed on the command line is actually // a file (that exists) and if an -ini key was also provided, then // add the file reference to the profile using the "-File" key. lbFirstArgIsFile = true; } else { // If no -ini key was passed, then assume the referenced file is // actually a profile file to be loaded. lsProfilePathFile = lsFirstArg; } } if ( null != lsProfilePathFile ) { // Load the referenced profile file. tvProfile loNewProfile = new tvProfile(); loNewProfile.eFileCreateAction = this.eFileCreateAction; loNewProfile.bUseXmlFiles = this.bUseXmlFiles; loNewProfile.bAddStandardDefaults = this.bAddStandardDefaults; loNewProfile.Load(lsProfilePathFile, tvProfileLoadActions.Overwrite); this.sActualPathFile = loNewProfile.sActualPathFile; this.sLoadedPathFile = loNewProfile.sLoadedPathFile; this.bExit = loNewProfile.bExit; if ( !this.bExit ) { this.bFileJustCreated = loNewProfile.bFileJustCreated; // We now need a slightly modified version of the given command line // (ie. sans the -ini key but with a -File key, if appropriate). tvProfile loCommandLine = new tvProfile(); loCommandLine.LoadFromCommandLineArray( this.sInputCommandLineArray, tvProfileLoadActions.Overwrite); if ( -1 != liIniKeyIndex ) loCommandLine.Remove(lsIniKeys[liIniKeyIndex]); if ( lbFirstArgIsFile ) loCommandLine.Add("-File", lsFirstArg); // Now merge in the original command line (with the above // adjustments). Command line items take precedence over file items. loNewProfile.LoadFromCommandLineArray(loCommandLine.sCommandLineArray(), tvProfileLoadActions.Merge); this.bSaveEnabled = loNewProfile.bSaveEnabled; // Reinitiallize the profile with the new combined results. this.LoadFromCommandLineArray(loNewProfile.sCommandLineArray(), tvProfileLoadActions.Overwrite); this.bDefaultFileReplaced = true; } loNewProfile.UnlockProfileFile(); } }