/*============================================================================= Project: SharpImage Module: RemoveFileConfiguration/Program.cs Language: C# Author: Dan Mueller $Date: 2007-04-11 16:26:16 +1000 (Wed, 11 Apr 2007) $ $Revision: 128 $ Copyright (c) Queensland University of Technology (QUT) 2007. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =============================================================================*/ using System; using System.IO; using System.Collections; using System.Collections.Generic; using System.Text; namespace RemoveFileConfiguration { class Program { static void Main(string[] args) { try { // args[0] = Full solution path // args[1] = FileToRemoveConfigurations (eg. CMakeLists.txt) if (args.Length <= 1) { Console.WriteLine("Usage: AbsoluteSolutionPath FileToRemoveConfigurations"); return; } // Get replacements from command line string pathSolution = args[0]; string fileToRemoveConfigs = args[1]; // Open solution for reading and get text Console.WriteLine("Reading solution: " + pathSolution); string bodySolution = File.ReadAllText(pathSolution); bodySolution = bodySolution.Replace("\r\n", "\r"); string[] linesSolution = bodySolution.Split('\r'); // Do for each project in solution foreach (string lineSolution in linesSolution) { if (lineSolution.StartsWith("Project(")) { //Get project path string[] linesProject = lineSolution.Split(','); string pathProject = linesProject[1].Trim(' ', '"', '.', '\\', '/'); pathProject = Path.Combine(Path.GetDirectoryName(pathSolution), pathProject); Console.WriteLine("Removing configurations for " + Path.GetFileName(pathProject)); RemoveFileConfiguration(pathProject, fileToRemoveConfigs); } } Console.WriteLine("Done."); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } public static void RemoveFileConfiguration(string pathProject, string fileToRemoveConfigs) { bool isInFile = false; bool isInFileConfiguration = false; bool writeLine = true; // Check that the project exists if (!File.Exists(pathProject)) { Console.WriteLine("Skipping " + Path.GetFileName(pathProject) + " because the path does not exist..."); return; } // Open project for reading and get text string bodyProject = File.ReadAllText(pathProject); bodyProject = bodyProject.Replace("\r\n", "\r"); string[] linesProject = bodyProject.Split('\r'); // Open project for writing StreamWriter writer = new StreamWriter(pathProject); // Output the adjusted/configured project foreach (string lineProject in linesProject) { if (lineProject.Contains("Path") && lineProject.Contains(fileToRemoveConfigs)) isInFile = true; else if (isInFile && lineProject.Contains("")) isInFile = false; else if (isInFile && !isInFileConfiguration && lineProject.Contains("")) { isInFileConfiguration = false; writeLine = false; } // Write the line if (!isInFileConfiguration && writeLine) writer.WriteLine(lineProject); writeLine = true; } // Clean up writer.Flush(); writer.Close(); Console.WriteLine("Done."); } } }