Example #1
0
        /// <summary>
        /// Called when the first instance is created
        /// </summary>
        /// <param name="e">Contains command line parameters</param>
        /// <returns>A System.Boolean that indicates if the application should continue starting up.</returns>
        protected override bool OnStartup(StartupEventArgs e)
        {
            Trace.AutoFlush = true;

            // Start the first instance of this app
            _wpfApp = new WpfApplication()
            {
                ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown
            };

            // Start a background thread for the named pipe server:
            Task.Run(() => _wpfApp.NamedPipeServer());

            if (e.CommandLine.Count > 0)
            {
                try
                {
                    var instanceParams = CgbUtils.ParseCommandLineArgs(e.CommandLine.ToArray());
                    _wpfApp.HandleNewInvocation(instanceParams);
                }
                catch (Exception ex)
                {
                    _wpfApp.AddToMessagesList(Message.Create(MessageType.Error, ex.Message, null));                     // TODO: Window with more info?
                    _wpfApp.ShowMessagesList();
                }
            }
            _wpfApp.Run();
            return(false);
        }
Example #2
0
        public static TextureCleanupData FindFullOutputPath(this IList <TextureCleanupData> collection, string path)
        {
            path = CgbUtils.NormalizePath(path);
            var existing = (from x in collection where x.FullOutputPathNormalized == path select x).FirstOrDefault();

            return(existing);
        }
 /// <summary>
 /// Determines whether or not there is a conflict with a different asset.
 /// A conflict means: same output path, but different input paths
 /// </summary>
 /// <param name="other">The other deployment to compare with</param>
 /// <returns>true if there is a conflict, false if everything is fine</returns>
 public virtual bool HasConflictWith(DeploymentBase other)
 {
     if (CgbUtils.NormalizePath(this.DesignatedOutputPath) == CgbUtils.NormalizePath(other.DesignatedOutputPath))
     {
         return(CgbUtils.NormalizePath(this._inputFile.FullName) != CgbUtils.NormalizePath(other._inputFile.FullName));
     }
     return(false);
 }
 /// <summary>
 /// The application is already running, but we're receiving new command line parameters to be handled...
 /// </summary>
 /// <param name="e">Contains the command line parameters, passed by the invoker</param>
 protected override void OnStartupNextInstance(StartupNextInstanceEventArgs e)
 {
     if (e.CommandLine.Count > 0)
     {
         try
         {
             var instanceParams = CgbUtils.ParseCommandLineArgs(e.CommandLine.ToArray());
             _wpfApp.HandleNewInvocation(instanceParams);
         }
         catch (Exception ex)
         {
             _wpfApp.AddToMessagesList(Message.Create(MessageType.Error, ex.Message, null));                     // TODO: Window with more info?
             _wpfApp.ShowMessagesList();
         }
     }
 }
Example #5
0
 private void RebuildOutputToInputPathRecords()
 {
     _outputToInputPathsNormalized = new List <TextureCleanupData>();
     foreach (var txp in _texturePaths)
     {
         var outPath    = GetOutputPathForTexture(txp);
         var outPathNrm = CgbUtils.NormalizePath(outPath);
         var existing   = _outputToInputPathsNormalized.FindFullOutputPath(outPathNrm);
         if (null == existing)
         {
             var inpPath    = GetInputPathForTexture(txp);
             var inpPathNrm = CgbUtils.NormalizePath(inpPath);
             _outputToInputPathsNormalized.Add(new TextureCleanupData
             {
                 FullOutputPathNormalized = outPathNrm,
                 FullInputPathNormalized  = inpPathNrm,
                 OriginalRelativePath     = txp
             });
         }
     }
 }
Example #6
0
		/// <summary>
		/// Handles ONE file deployment
		/// </summary>
		/// <param name="config">The build's config parameters</param>
		/// <param name="filePath">Path to the input file</param>
		/// <param name="filterPath">Associated filter path of the file</param>
		/// <param name="modDeployments">List of deployments; this will be modified, i.e. a deployment will be added to this list in the success-case</param>
		/// <param name="modFileDeployments">List of FILE deployments; this will be modified. A deployment can affect multiple files, which are all added to this list in the success-case.</param>
		/// <param name="modWindowsToShowFor">List of single file deployments which an emergency-window has to be opened for; this will be modified.</param>
		public void HandleFileToDeploy(
			InvocationParams config, string filePath, string filterPath,
			IList<IFileDeployment> modDeployments, IList<FileDeploymentData> modFileDeployments, IList<FileDeploymentData> modWindowsToShowFor,
			bool doNotOverwriteExisting = false)
		{
			IFileDeployment savedForUseInException = null;
			try
			{
				lock (_namedPipeSync)
				{
					_applicationStatus = $"Deploying files from '{new FileInfo(config.VcxprojPath).Name}' (currently working on '{new FileInfo(filePath).Name}')...";
				}

				savedForUseInException = null;
				CgbUtils.PrepareDeployment(
					config,
					filePath, filterPath,
					out var deployment);

				// It can be null, if it is not an asset/shader that should be deployed
				if (null == deployment)
				{
					return;
				}

				savedForUseInException = deployment;

				// Do it!
				if (doNotOverwriteExisting)
				{
					// ...unless we shouldn't do it!
					if (File.Exists(deployment.DesignatedOutputPath))
					{
                        Trace.TraceInformation($"Not deploying file to '{deployment.DesignatedOutputPath}' because it already exists (and don't overwrite flag is set).");
						return;
					}
				}

				// Before deploying, check for conflicts and try to resolve them (which actually is only implemented for Models)
				bool repeatChecks;
				var deploymentBase = (DeploymentBase)deployment;
				var deploymentModel = deployment as ModelDeployment;
				var deploymentsToIssueWarningsFor = new HashSet<DeploymentBase>();
				do
				{
					repeatChecks = false;
					foreach (var otherDeployment in modDeployments)
					{
						var otherDeploymentBase = (DeploymentBase)otherDeployment;
						if (deploymentBase.HasConflictWith(otherDeploymentBase))
						{
							if (null != deploymentModel && otherDeployment is ModelDeployment otherDeploymentModel)
							{
								deploymentModel.ResolveConflictByMovingThisToSubfolder();
								repeatChecks = true;
								break;
							}
							else
							{
								deploymentsToIssueWarningsFor.Add(otherDeploymentBase);
							}
						}
					}
				} while (repeatChecks);

				// Do we have to show any warnings?
				if (deploymentsToIssueWarningsFor.Count > 0)
				{
					foreach (var otherDeploymentBase in deploymentsToIssueWarningsFor)
					{
						AddToMessagesList(Message.Create(MessageType.Warning, $"File '{deploymentBase.InputFilePath}' has an unresolvable conflict with file '{otherDeploymentBase.InputFilePath}'.", null, deploymentBase.InputFilePath) /* TODO: ADD INSTANCE HERE */);
					}
					ShowMessagesList();
				}

				// And, before deploying, try to optimize!
				foreach (var otherDeployment in modDeployments)
				{
					System.Diagnostics.Debug.Assert(deployment != otherDeployment);
					var otherDeploymentBase = (DeploymentBase)otherDeployment;
					if (null != deploymentModel && otherDeployment is ModelDeployment otherDeploymentModel)
					{
						deploymentModel.KickOutAllTexturesWhichAreAvailableInOther(otherDeploymentModel);
					}
				}

				deployment.Deploy();

				foreach (var deployedFile in deployment.FilesDeployed)
				{
					// For the current files list:
					modFileDeployments.Add(deployedFile);

					var deploymentHasErrors = deployedFile.Messages.ContainsMessagesOfType(MessageType.Error);
					var deploymentHasWarnings = deployedFile.Messages.ContainsMessagesOfType(MessageType.Warning);

					// Show errors/warnings in window immediately IF this behavior has been opted-in via our settings
					if (deploymentHasWarnings || deploymentHasErrors)
					{
						if ((CgbPostBuildHelper.Properties.Settings.Default.ShowWindowForVkShaderDeployment && deployment is Deployers.VkShaderDeployment)
							|| (CgbPostBuildHelper.Properties.Settings.Default.ShowWindowForGlShaderDeployment && deployment is Deployers.GlShaderDeployment)
							|| (CgbPostBuildHelper.Properties.Settings.Default.ShowWindowForModelDeployment && deployment is Deployers.ModelDeployment))
						{
							modWindowsToShowFor.Add(deployedFile);
						}
					}
				}

				modDeployments.Add(deployment);
			}
			catch (UnauthorizedAccessException uaex)
			{
				if (uaex.Message.IndexOf(".dll", StringComparison.InvariantCultureIgnoreCase) >= 0 
					&& null != savedForUseInException
					&& 0 != savedForUseInException.FilesDeployed.Count
					&& CgbPostBuildHelper.Properties.Settings.Default.HideAccessDeniedErrorsForDlls)
				{
					savedForUseInException.FilesDeployed.Last().Messages.Add(Message.Create(MessageType.Information, uaex.Message, null));
					foreach (var deployedFile in savedForUseInException.FilesDeployed)
					{
						modFileDeployments.Add(deployedFile);
					}
					modDeployments.Add(savedForUseInException);
				}
				else
				{
					AddToMessagesList(Message.Create(MessageType.Error, uaex.Message, null), config); // TODO: Window with more info?
					ShowMessagesList();
				}
			}
			catch (Exception ex)
			{
				AddToMessagesList(Message.Create(MessageType.Error, ex.Message, null), config); // TODO: Window with more info?
				ShowMessagesList();
			}
		}