Beispiel #1
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(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.13\build\native\include\"));
            generator.IncludeDirectories.Add(Path.Combine(sourceDirectory, @"packages\libimobiledevice.1.2.1.73\build\native\include\"));
            generator.IncludeDirectories.Add(Path.Combine(sourceDirectory, @"packages\libplist.1.12.73\build\native\include"));
            generator.IncludeDirectories.Add(Path.Combine(sourceDirectory, @"packages\libusbmuxd.1.0.10.13\build\native\include"));

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

            var files = new List <string>();

            files.Add(Path.Combine(sourceDirectory, @"packages\libusbmuxd.1.0.10.13\build\native\include\usbmuxd.h"));
            files.Add(Path.Combine(sourceDirectory, @"packages\libplist.1.12.73\build\native\include\plist\plist.h"));

            var iMobileDeviceDirectory = Path.Combine(sourceDirectory, @"packages\libimobiledevice.1.2.1.73\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;
                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"));
        }
Beispiel #2
0
        public static int Main(string[] args)
        {
            CommandLineApplication commandLineApplication =
                new CommandLineApplication(throwOnUnexpectedArg: false);

            commandLineApplication.Name = "iMobileDevice.Generator";
            commandLineApplication.HelpOption("-?|-h|--help");

            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 includeArgument = runCommand.Option(
                    "-i|--include <dir>",
                    "Include directory to use. Defaults to the include directory in VCPKG_ROOT.",
                    CommandOptionType.SingleValue);

                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"));

                    string sourceDir = null;

                    if (includeArgument.HasValue())
                    {
                        sourceDir = includeArgument.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)}");
                        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);
                });
            });

            return(commandLineApplication.Execute(args));
        }