source: trunk/eraser/Eraser.Util/Shell.cs @ 2002

Revision 2002, 2.5 KB checked in by lowjoel, 5 years ago (diff)

Implemented response file support to allow for very long command lines.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1/*
2 * $Id$
3 * Copyright 2008-2010 The Eraser Project
4 * Original Author: Joel Low <lowjoel@users.sourceforge.net>
5 * Modified By:
6 *
7 * This file is part of Eraser.
8 *
9 * Eraser is free software: you can redistribute it and/or modify it under the
10 * terms of the GNU General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option) any later
12 * version.
13 *
14 * Eraser is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 *
18 * A copy of the GNU General Public License can be found at
19 * <http://www.gnu.org/licenses/>.
20 */
21
22using System;
23using System.Collections.Generic;
24using System.Text;
25
26using System.Runtime.InteropServices;
27using Microsoft.Win32;
28
29namespace Eraser.Util
30{
31    public static class Shell
32    {
33        /// <summary>
34        /// Gets or sets whether low disk space notifications are enabled for the
35        /// current user.
36        /// </summary>
37        public static bool LowDiskSpaceNotificationsEnabled
38        {
39            get
40            {
41                using (RegistryKey key = Registry.CurrentUser.OpenSubKey(
42                    "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"))
43                {
44                    if (key == null)
45                        return true;
46                    return !Convert.ToBoolean(key.GetValue("NoLowDiskSpaceChecks", false));
47                }
48            }
49            set
50            {
51                RegistryKey key = null;
52                try
53                {
54                    key = Registry.CurrentUser.OpenSubKey(
55                        "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", true);
56                    if (key == null)
57                        key = Registry.CurrentUser.CreateSubKey(
58                            "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer");
59                    key.SetValue("NoLowDiskSpaceChecks", !value);
60                }
61                finally
62                {
63                    if (key != null)
64                        key.Close();
65                }
66            }
67        }
68
69        /// <summary>
70        /// Parses the provided command line into its constituent arguments.
71        /// </summary>
72        /// <param name="commandLine">The command line to parse.</param>
73        /// <returns>The arguments specified in the command line</returns>
74        public static string[] ParseCommandLine(string commandLine)
75        {
76            int argc = 0;
77            IntPtr argv = NativeMethods.CommandLineToArgvW(commandLine, out argc);
78            string[] result = new string[argc];
79
80            //Get the pointers to the arguments, then read the string.
81            for (int i = 0; i < argc; ++i)
82                result[i] = Marshal.PtrToStringUni(Marshal.ReadIntPtr(argv, i * IntPtr.Size));
83
84            //Free the memory
85            NativeMethods.LocalFree(argv);
86
87            return result;
88        }
89    }
90}
Note: See TracBrowser for help on using the repository browser.