示例#1
0
        private void ExportDistro(DistroProperties distroItem, string filePath, bool revealAfterComplete)
        {
            if (distroItem == null)
            {
                return;
            }

            ProcessStartInfo startInfo;

            startInfo = new ProcessStartInfo(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "wsl.exe"),
                $@"--export {distroItem.DistroName} {filePath}")
            {
                UseShellExecute  = false,
                WorkingDirectory = Path.GetDirectoryName(filePath),
            };

            var proc = Process.Start(startInfo);

            proc.WaitForExit();

            if (revealAfterComplete)
            {
                var revealStartInfo = new ProcessStartInfo(
                    Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe"),
                    $@"/select,{filePath}")
                {
                    UseShellExecute  = false,
                    WorkingDirectory = Path.GetDirectoryName(filePath),
                };

                Process.Start(revealStartInfo);
            }
        }
示例#2
0
        private void OpenWslFolder(DistroProperties distro)
        {
            var startInfo = new ProcessStartInfo(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "explorer.exe"),
                $@"\\wsl$\{distro.DistroName}")
            {
                UseShellExecute = false,
            };

            Process.Start(startInfo);
        }
示例#3
0
        private void UnregisterDistro(DistroProperties distroItem)
        {
            if (distroItem == null)
            {
                return;
            }

            ProcessStartInfo startInfo;

            startInfo = new ProcessStartInfo(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "wsl.exe"),
                $@"--unregister {distroItem.DistroName}")
            {
                UseShellExecute = false,
            };

            var proc = Process.Start(startInfo);

            proc.WaitForExit();
        }
示例#4
0
        private bool CreateDistroShortcut(DistroProperties selectedDistro, string targetFilePath)
        {
            var shortcut = (IWshShortcut)wscriptShellType.InvokeMember(
                "CreateShortcut",
                BindingFlags.InvokeMethod,
                null, shellObject,
                new object[] { targetFilePath });

            shortcut.Description = selectedDistro.DistroName;
            shortcut.TargetPath  = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.System),
                "wsl.exe");
            shortcut.WorkingDirectory = Environment.GetFolderPath(
                Environment.SpecialFolder.UserProfile);
            shortcut.Arguments    = $@"-d {selectedDistro.DistroName}";
            shortcut.IconLocation = Path.Combine(
                SharedRoutines.GetIconDirectoryPath(),
                SharedRoutines.GetImageKey(selectedDistro.DistroName) + ".ico");
            shortcut.Save();

            return(File.Exists(targetFilePath));
        }
示例#5
0
        private void OpenWslConfig(DistroProperties distro)
        {
            var wslConfPath = $@"\\wsl$\{distro.DistroName}\etc\wsl.conf";

            if (!File.Exists(wslConfPath))
            {
                try { File.WriteAllText(wslConfPath, "# https://docs.microsoft.com/en-us/windows/wsl/wsl-config#set-wsl-launch-settings\n", Encoding.ASCII); }
                catch { }
            }

            if (!File.Exists(wslConfPath))
            {
                return;
            }

            var startInfo = new ProcessStartInfo(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Windows), "notepad.exe"),
                wslConfPath)
            {
                UseShellExecute = false,
            };

            Process.Start(startInfo);
        }