Ejemplo n.º 1
0
        public static int Main(string[] args)
        {
            CommandLineApplication commandLineApplication =
                new CommandLineApplication(throwOnUnexpectedArg: true);

            commandLineApplication.Name = ThisAssembly.AssemblyName;
            commandLineApplication.HelpOption("-?|-h|--help");
            commandLineApplication.ShortVersionGetter = () => ThisAssembly.AssemblyFileVersion;
            commandLineApplication.LongVersionGetter  = () => ThisAssembly.AssemblyInformationalVersion;

            commandLineApplication.Command(
                "generate",
                (runCommand) =>
            {
                runCommand.Description = "Generates the Interop source for imobiledevice-net based on the libimobiledevice headers";

                CommandOption outputArgument = runCommand.Option(
                    "-o|--output <dir>",
                    "The output directory. The C# code will be generated in this directory.",
                    CommandOptionType.SingleValue);

                CommandOption headerArgument = runCommand.Option(
                    "-s|--source <dir>",
                    "Include directory to use, which contains the libimobiledevice headers. Defaults to the include directory in VCPKG_ROOT.",
                    CommandOptionType.SingleValue);

                CommandOption includeArgument = runCommand.Option(
                    "-i|--include <dir>",
                    "Include directory to use. Defaults to the include directory in VCPKG_ROOT.",
                    CommandOptionType.MultipleValue);

                runCommand.HelpOption("-? | -h | --help");

                runCommand.OnExecute(() =>
                {
                    string targetDirectory = @"..\..\..\..\..\iMobileDevice-net";
                    if (outputArgument.HasValue())
                    {
                        targetDirectory = outputArgument.Value();
                    }

                    targetDirectory = Path.GetFullPath(targetDirectory);

                    RestoreClang();

                    ModuleGenerator generator = new ModuleGenerator();
                    generator.IncludeDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Microsoft Visual Studio 14.0\VC\include"));
                    generator.IncludeDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Microsoft Visual Studio\Shared\14.0\VC\include"));
                    generator.IncludeDirectories.Add(GetWindowsKitUcrtFolder());
                    generator.IncludeDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Windows Kits", "8.1", "include", "shared"));

                    if (includeArgument.HasValue())
                    {
                        foreach (var path in includeArgument.Values)
                        {
                            generator.IncludeDirectories.Add(path);
                        }
                    }

                    string sourceDir = null;

                    if (headerArgument.HasValue())
                    {
                        sourceDir = headerArgument.Value();
                    }
                    else
                    {
                        var vcpkgPath = Environment.GetEnvironmentVariable("VCPKG_ROOT");

                        if (vcpkgPath == null)
                        {
                            Console.Error.WriteLine("Please set the VCPKG_ROOT environment variable to the folder where you've installed VCPKG.");
                            return(-1);
                        }

                        vcpkgPath = Path.Combine(vcpkgPath, "installed", "x86-windows", "include");
                        Console.WriteLine($"Reading include files from {vcpkgPath}");
                        sourceDir = vcpkgPath;
                    }

                    generator.IncludeDirectories.Add(sourceDir);

                    Console.WriteLine($"Writing the C# files to: {targetDirectory}");

                    Collection <string> names = new Collection <string>();

                    var files = new List <string>();
                    files.Add(Path.Combine(sourceDir, "usbmuxd.h"));
                    files.Add(Path.Combine(sourceDir, "plist/plist.h"));
                    files.Add(Path.Combine(sourceDir, "libideviceactivation.h"));
                    files.Add(Path.Combine(sourceDir, "libirecovery.h"));
                    var iMobileDeviceDirectory = Path.Combine(sourceDir, "libimobiledevice");
                    files.Add(Path.Combine(iMobileDeviceDirectory, "libimobiledevice.h"));
                    files.Add(Path.Combine(iMobileDeviceDirectory, "lockdown.h"));
                    files.Add(Path.Combine(iMobileDeviceDirectory, "afc.h"));

                    var iMobileDeviceFileNames = Directory.GetFiles(iMobileDeviceDirectory, "*.h")
                                                 .Where(f => !files.Contains(f, StringComparer.OrdinalIgnoreCase));

                    files.AddRange(iMobileDeviceFileNames);

                    foreach (var file in files)
                    {
                        Console.WriteLine($"Processing {Path.GetFileName(file)}");

                        if (!File.Exists(file))
                        {
                            Console.WriteLine($"WARNING: Skipping file {file} because it does not exist.");
                            continue;
                        }

                        generator.InputFile = file;

                        if (string.Equals(Path.GetFileName(file), "libideviceactivation.h", StringComparison.OrdinalIgnoreCase))
                        {
                            generator.Generate(targetDirectory, "ideviceactivation");
                        }
                        else if (string.Equals(Path.GetFileName(file), "plist.h", StringComparison.OrdinalIgnoreCase))
                        {
                            generator.Generate(targetDirectory, "plist");
                        }
                        else if (string.Equals(Path.GetFileName(file), "usbmuxd.h", StringComparison.OrdinalIgnoreCase))
                        {
                            generator.Generate(targetDirectory, "usbmuxd");
                        }
                        else if (string.Equals(Path.GetFileName(file), "libirecovery.h", StringComparison.OrdinalIgnoreCase))
                        {
                            generator.Generate(targetDirectory, "irecovery");
                        }
                        else
                        {
                            generator.Generate(targetDirectory);
                        }

                        generator.Types.Clear();

                        names.Add(generator.Name);
                    }

                    ApiGenerator apiGenerator = new ApiGenerator();
                    apiGenerator.Generate(names, targetDirectory);

                    return(0);
                });
            });

            Console.WriteLine(ThisAssembly.AssemblyName);
            commandLineApplication.ShowVersion();

            var exit = commandLineApplication.Execute(args);

            Console.WriteLine($"Exiting with code {exit}");
            return(exit);
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            string sourceDirectory = null;
            string targetDirectory = null;

            if (args.Length >= 1)
            {
                sourceDirectory = args[0];
            }
            else
            {
                // Default value so that you can just F5 from within Visual Studio
                sourceDirectory = @"..\..\..\..\";
            }

            if (args.Length >= 2)
            {
                targetDirectory = args[1];
            }
            else
            {
                targetDirectory = @"..\..\..\..\iMobileDevice-net";
            }

            sourceDirectory = Path.GetFullPath(sourceDirectory);
            targetDirectory = Path.GetFullPath(targetDirectory);

            Console.WriteLine($"Reading libimobiledevice headers from: {sourceDirectory}");
            Console.WriteLine($"Writing the C# files to: {targetDirectory}");

            ModuleGenerator generator = new ModuleGenerator();

            generator.IncludeDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Microsoft Visual Studio 14.0\VC\include"));
            generator.IncludeDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Microsoft Visual Studio\Shared\14.0\VC\include"));
            generator.IncludeDirectories.Add(GetWindowsKitUcrtFolder());
            generator.IncludeDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Windows Kits", "8.1", "include", "shared"));
            generator.IncludeDirectories.Add(Path.Combine(sourceDirectory, @"packages\libusbmuxd.1.0.10.92\build\native\include\"));
            generator.IncludeDirectories.Add(Path.Combine(sourceDirectory, @"packages\libimobiledevice.1.2.1.196\build\native\include\"));
            generator.IncludeDirectories.Add(Path.Combine(sourceDirectory, @"packages\libplist.2.0.1.171\build\native\include"));
            generator.IncludeDirectories.Add(Path.Combine(sourceDirectory, @"packages\libideviceactivation.1.0.0.23\build\native\include\libideviceactivation"));

            Collection <string> names = new Collection <string>();

            var files = new List <string>();

            files.Add(Path.Combine(sourceDirectory, @"packages\libusbmuxd.1.0.10.92\build\native\include\usbmuxd.h"));
            files.Add(Path.Combine(sourceDirectory, @"packages\libplist.2.0.1.171\build\native\include\plist\plist.h"));
            files.Add(Path.Combine(sourceDirectory, @"packages\libideviceactivation.1.0.0.23\build\native\include\libideviceactivation\libideviceactivation.h"));

            var iMobileDeviceDirectory = Path.Combine(sourceDirectory, @"packages\libimobiledevice.1.2.1.196\build\native\include\libimobiledevice");

            files.Add(Path.Combine(iMobileDeviceDirectory, "libimobiledevice.h"));
            files.Add(Path.Combine(iMobileDeviceDirectory, "lockdown.h"));
            files.Add(Path.Combine(iMobileDeviceDirectory, "afc.h"));

            var iMobileDeviceFileNames = Directory.GetFiles(iMobileDeviceDirectory, "*.h")
                                         .Where(f => !files.Contains(f, StringComparer.OrdinalIgnoreCase));

            files.AddRange(iMobileDeviceFileNames);

            foreach (var file in files)
            {
                Console.WriteLine($"Processing {Path.GetFileName(file)}");
                generator.InputFile = file;

                if (string.Equals(Path.GetFileName(file), "libideviceactivation.h", StringComparison.OrdinalIgnoreCase))
                {
                    generator.Generate(targetDirectory, "ideviceactivation");
                }
                else
                {
                    generator.Generate(targetDirectory);
                }

                generator.Types.Clear();

                names.Add(generator.Name);
            }

            ApiGenerator apiGenerator = new ApiGenerator();

            apiGenerator.Generate(names, targetDirectory);

            // StylecopFixer.Run(Path.Combine(targetDirectory, "iMobileDevice.csproj"));
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            string sourceDirectory = null;
            string targetDirectory = null;

            if (args.Length >= 1)
            {
                sourceDirectory = args[0];
            }
            else
            {
                // Default value so that you can just F5 from within Visual Studio
                sourceDirectory = @"..\..\..\..\";
            }

            if (args.Length >= 2)
            {
                targetDirectory = args[1];
            }
            else
            {
                targetDirectory = @"..\..\..\..\..\iMobileDevice-net";
            }

            RestoreClang();

            var packagesDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages");

            sourceDirectory = Path.GetFullPath(sourceDirectory);
            targetDirectory = Path.GetFullPath(targetDirectory);

            Console.WriteLine($"Reading libimobiledevice headers from: {sourceDirectory}");
            Console.WriteLine($"Writing the C# files to: {targetDirectory}");

            var vcpkgPath = Environment.GetEnvironmentVariable("VCPKG_ROOT");

            vcpkgPath = Path.Combine(vcpkgPath, "installed", "x86-windows", "include");
            Console.WriteLine($"Reading include files from {vcpkgPath}");

            ModuleGenerator generator = new ModuleGenerator();

            generator.IncludeDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Microsoft Visual Studio 14.0\VC\include"));
            generator.IncludeDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Microsoft Visual Studio\Shared\14.0\VC\include"));
            generator.IncludeDirectories.Add(GetWindowsKitUcrtFolder());
            generator.IncludeDirectories.Add(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Windows Kits", "8.1", "include", "shared"));
            generator.IncludeDirectories.Add(Path.Combine(vcpkgPath));

            Collection <string> names = new Collection <string>();

            var files = new List <string>();

            files.Add(Path.Combine(packagesDirectory, Path.Combine(vcpkgPath, "usbmuxd.h")));
            files.Add(Path.Combine(packagesDirectory, Path.Combine(vcpkgPath, "plist/plist.h")));
            files.Add(Path.Combine(packagesDirectory, Path.Combine(vcpkgPath, "libideviceactivation.h")));

            var iMobileDeviceDirectory = Path.Combine(vcpkgPath, "libimobiledevice");

            files.Add(Path.Combine(iMobileDeviceDirectory, "libimobiledevice.h"));
            files.Add(Path.Combine(iMobileDeviceDirectory, "lockdown.h"));
            files.Add(Path.Combine(iMobileDeviceDirectory, "afc.h"));

            var iMobileDeviceFileNames = Directory.GetFiles(iMobileDeviceDirectory, "*.h")
                                         .Where(f => !files.Contains(f, StringComparer.OrdinalIgnoreCase));

            files.AddRange(iMobileDeviceFileNames);

            foreach (var file in files)
            {
                Console.WriteLine($"Processing {Path.GetFileName(file)}");
                generator.InputFile = file;

                if (string.Equals(Path.GetFileName(file), "libideviceactivation.h", StringComparison.OrdinalIgnoreCase))
                {
                    generator.Generate(targetDirectory, "ideviceactivation");
                }
                else
                {
                    generator.Generate(targetDirectory);
                }

                generator.Types.Clear();

                names.Add(generator.Name);
            }

            ApiGenerator apiGenerator = new ApiGenerator();

            apiGenerator.Generate(names, targetDirectory);
        }