using System; using System.Collections.Generic; using System.Text; using System.IO; using System.Windows.Forms; using System.Diagnostics; using System.Runtime.InteropServices; using System.Reflection; namespace wix { class Program { /// /// The operation completed successfully. /// public const int ERROR_SUCCESS = 0; /// /// Incorrect function. /// public const int ERROR_INVALID_FUNCTION = 1; /// /// The system cannot find the file specified. /// public const int ERROR_FILE_NOT_FOUND = 2; /// /// The system cannot find the path specified. /// public const int ERROR_PATH_NOT_FOUND = 3; /// /// The system cannot open the file. /// public const int ERROR_TOO_MANY_OPEN_FILES = 4; /// /// Access is denied. /// public const int ERROR_ACCESS_DENIED = 5; const Int32 DRIVER_PACKAGE_REPAIR = 0x00000001; const Int32 DRIVER_PACKAGE_SILENT = 0x00000002; const Int32 DRIVER_PACKAGE_FORCE = 0x00000004; const Int32 DRIVER_PACKAGE_ONLY_IF_DEVICE_PRESENT = 0x00000008; const Int32 DRIVER_PACKAGE_LEGACY_MODE = 0x00000010; const Int32 DRIVER_PACKAGE_DELETE_FILES = 0x00000020; [DllImport("DIFXApi.dll", CharSet = CharSet.Unicode)] public static extern Int32 DriverPackagePreinstall(string DriverPackageInfPath, Int32 Flags); static void driverinstall() { int result = DriverPackagePreinstall(@"..\Driver\Arduino MEGA 2560.inf", 0); if (result != 0) MessageBox.Show("Driver installation failed. " + result); } static int no = 0; static StreamWriter sw; static List components = new List(); static string mainexeid = ""; static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Bad Directory"); return; } if (args[0] == "driver") { driverinstall(); return; } string path = args[0]; //Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar+ string file = "installer.wxs"; sw = new StreamWriter(file); header(); sw.WriteLine(""); sw.WriteLine(@" "); //sw.WriteLine(""); dodirectory(path, 0); footer(); sw.Close(); /* System.Diagnostics.Process P = new System.Diagnostics.Process(); P.StartInfo.FileName = "cmd.exe"; P.StartInfo.Arguments = " /c \"" + Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "installer.bat\""; P.StartInfo.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath); P.Start(); */ //Console.ReadLine(); string exepath = Path.GetFullPath(path) + Path.DirectorySeparatorChar + "ArdupilotMegaPlanner.exe"; string version = Assembly.LoadFile(exepath).GetName().Version.ToString(); System.Diagnostics.FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(exepath); StreamWriter st = new StreamWriter("create.bat", false); st.WriteLine("del installer.wixobj"); st.WriteLine(@"""%wix%\bin\candle"" installer.wxs -ext WiXNetFxExtension -ext WixDifxAppExtension -ext WixUIExtension.dll -ext WixUtilExtension"); st.WriteLine(@"""%wix%\bin\light"" installer.wixobj ""%wix%\bin\difxapp_x86.wixlib"" -o MissionPlanner32-" + fvi.FileVersion + ".msi -ext WiXNetFxExtension -ext WixDifxAppExtension -ext WixUIExtension.dll -ext WixUtilExtension"); st.WriteLine(@"""%wix%\bin\light"" installer.wixobj ""%wix%\bin\difxapp_x64.wixlib"" -o MissionPlanner64-" + fvi.FileVersion + ".msi -ext WiXNetFxExtension -ext WixDifxAppExtension -ext WixUIExtension.dll -ext WixUtilExtension"); st.WriteLine(@"""C:\Program Files\7-Zip\7z.exe"" a -tzip -xr!*.log -xr!ArdupilotPlanner.log* -xr!*.tlog -xr!config.xml -xr!gmapcache -xr!eeprom.bin -xr!dataflash.bin -xr!*.new ""Mission Planner " + fvi.FileVersion + @".zip"" ..\bin\release\*"); st.WriteLine("pause"); st.WriteLine("googlecode_upload.py -s \"Mission Planner zip file, " + fvi.FileVersion + "\" -p ardupilot-mega \"Mission Planner " + fvi.FileVersion + @".zip"""); st.WriteLine("googlecode_upload.py -s \"Mission Planner installer (32-bit)\" -p ardupilot-mega MissionPlanner32-" + fvi.FileVersion + ".msi"); st.WriteLine("googlecode_upload.py -s \"Mission Planner installer (64-bit)\" -p ardupilot-mega MissionPlanner64-" + fvi.FileVersion + ".msi"); st.Close(); runProgram("create.bat"); } static void runProgram(string run) { System.Diagnostics.Process P = new System.Diagnostics.Process(); P.StartInfo.FileName = run; // P.StartInfo.WorkingDirectory = Path.GetDirectoryName(Application.ExecutablePath); P.StartInfo.UseShellExecute = true; P.Start(); } static void header() { string newid = System.Guid.NewGuid().ToString(); newid = "*"; StreamReader sr = new StreamReader(File.OpenRead("../Properties/AssemblyInfo.cs")); string version = "0"; while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line.Contains("AssemblyFileVersion")) { string[] items = line.Split(new char[] { '"' },StringSplitOptions.RemoveEmptyEntries); version = items[1]; break; } } sr.Close(); string data = @" "; sw.WriteLine(data); } static void footer() { string data = @" "; sw.WriteLine(data); foreach (string comp in components) { sw.WriteLine(@""); } data = @" WIXUI_EXITDIALOGOPTIONALCHECKBOX = 1 and NOT Installed "; sw.WriteLine(data); } static void dodirectory(string path, int level = 1) { string[] dirs = Directory.GetDirectories(path); if (level != 0) sw.WriteLine(""); string[] files = Directory.GetFiles(path); no++; sw.WriteLine(""); components.Add("_comp"+no); foreach (string filepath in files) { if (filepath.ToLower().EndsWith("release\\config.xml") || filepath.ToLower().Contains("ardupilotplanner.log") || filepath.ToLower().Contains("dataflash.bin") || filepath.ToLower().Contains(".etag")) continue; no++; if (filepath.EndsWith("ArdupilotMegaPlanner.exe")) { mainexeid = "_" + no; sw.WriteLine(" "); } else { sw.WriteLine(""); } } sw.WriteLine(""); foreach (string dir in dirs) { if (dir.ToLower().EndsWith("gmapcache") || dir.ToLower().EndsWith("srtm") || dir.ToLower().EndsWith("logs")) continue; dodirectory(dir); } if (level != 0) sw.WriteLine(""); } static string fixname(string name) { name = name.Replace("-", "_"); name = name.Replace(" ", "_"); name = name.Replace(" ", "_"); return name; } } }