Advertisement
Shevek

proxy.patch

Dec 31st, 2012
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 14.64 KB | None | 0 0
  1. Index: core/details/MeGUISettings.cs
  2. ===================================================================
  3. --- core/details/MeGUISettings.cs   (revision 2258)
  4. +++ core/details/MeGUISettings.cs   (working copy)
  5. @@ -56,7 +56,7 @@
  6.          private bool recalculateMainMovieBitrate, autoForceFilm, autoStartQueue, enableMP3inMP4, autoOpenScript,
  7.                       overwriteStats, keep2of3passOutput, autoUpdate, deleteCompletedJobs, deleteIntermediateFiles,
  8.                       deleteAbortedOutput, openProgressWindow, useadvancedtooltips, autoSelectHDStreams, autoscroll,
  9. -                     alwaysOnTop, safeProfileAlteration, usehttpproxy, addTimePosition, alwaysbackupfiles, bUseITU,
  10. +                     alwaysOnTop, safeProfileAlteration, addTimePosition, alwaysbackupfiles, bUseITU,
  11.                       forcerawavcextension, bAutoLoadDG, bAutoStartQueueStartup, bAlwaysMuxMKV, b64bitX264, bUseQAAC,
  12.                       bEnsureCorrectPlaybackSpeed, bOpenAVSInThread, bUseDGIndexNV, bUseNeroAacEnc;
  13.          private ulong audioSamplesPerUpdate;
  14. @@ -78,6 +78,7 @@
  15.          private Dar[] customDARs;
  16.          private OCGUIMode ocGUIMode;
  17.          private AfterEncoding afterEncoding;
  18. +        private ProxyMode httpProxyMode;
  19.          #endregion
  20.          public MeGUISettings()
  21.         {
  22. @@ -155,7 +156,7 @@
  23.              audioExtension = "";
  24.              safeProfileAlteration = false;
  25.              alwaysOnTop = false;
  26. -            usehttpproxy = false;
  27. +            httpProxyMode = ProxyMode.None;
  28.              httpproxyaddress = "";
  29.              httpproxyport = "";
  30.              httpproxyuid = "";
  31. @@ -1036,10 +1037,10 @@
  32.          /// <summary>
  33.          /// gets / sets the default settings for the Proxy
  34.          /// </summary>
  35. -        public bool UseHttpProxy
  36. +        public ProxyMode HttpProxyMode
  37.          {
  38. -            get { return usehttpproxy; }
  39. -            set { usehttpproxy = value; }
  40. +            get { return httpProxyMode; }
  41. +            set { httpProxyMode = value; }
  42.          }
  43.          /// <summary>
  44.          /// gets / sets the default settings for the Proxy Adress
  45. @@ -1204,4 +1205,5 @@
  46.          #endregion
  47.      }
  48.      public enum AfterEncoding { DoNothing = 0, Shutdown = 1, RunCommand = 2, CloseMeGUI = 3 }
  49. +    public enum ProxyMode { None = 0, SystemProxy = 1, CustomProxy = 2, CustomProxyWithLogin = 3 }
  50.  }
  51. Index: core/gui/SettingsForm.cs
  52. ===================================================================
  53. --- core/gui/SettingsForm.cs    (revision 2258)
  54. +++ core/gui/SettingsForm.cs    (working copy)
  55. @@ -95,7 +95,6 @@
  56.          private Label label20;
  57.          private Label label19;
  58.          private Label label18;
  59. -        private CheckBox cbx_usehttpproxy;
  60.          private TextBox txt_httpproxypwd;
  61.          private TextBox txt_httpproxyport;
  62.          private GroupBox gbDefaultOutput;
  63. @@ -141,6 +140,8 @@
  64.          private Label lblNero;
  65.          private CheckBox useDGIndexNV;
  66.          private CheckBox useQAAC;
  67. +        private Label label1;
  68. +        private ComboBox cbHttpProxyMode;
  69.          private XmlDocument ContextHelp = new XmlDocument();
  70.         #region start / stop
  71.         public SettingsForm()
  72. @@ -272,6 +273,8 @@
  73.              this.clearDefaultOutputDir = new System.Windows.Forms.Button();
  74.              this.tabPage3 = new System.Windows.Forms.TabPage();
  75.              this.groupBox2 = new System.Windows.Forms.GroupBox();
  76. +            this.label1 = new System.Windows.Forms.Label();
  77. +            this.cbHttpProxyMode = new System.Windows.Forms.ComboBox();
  78.              this.txt_httpproxyport = new System.Windows.Forms.TextBox();
  79.              this.txt_httpproxypwd = new System.Windows.Forms.TextBox();
  80.              this.txt_httpproxyuid = new System.Windows.Forms.TextBox();
  81. @@ -280,7 +283,6 @@
  82.              this.label20 = new System.Windows.Forms.Label();
  83.              this.label19 = new System.Windows.Forms.Label();
  84.              this.label18 = new System.Windows.Forms.Label();
  85. -            this.cbx_usehttpproxy = new System.Windows.Forms.CheckBox();
  86.              this.gbVideoPreview = new System.Windows.Forms.GroupBox();
  87.              this.chkEnsureCorrectPlaybackSpeed = new System.Windows.Forms.CheckBox();
  88.              this.cbAddTimePos = new System.Windows.Forms.CheckBox();
  89. @@ -807,6 +809,8 @@
  90.              //
  91.              // groupBox2
  92.              //
  93. +            this.groupBox2.Controls.Add(this.label1);
  94. +            this.groupBox2.Controls.Add(this.cbHttpProxyMode);
  95.              this.groupBox2.Controls.Add(this.txt_httpproxyport);
  96.              this.groupBox2.Controls.Add(this.txt_httpproxypwd);
  97.              this.groupBox2.Controls.Add(this.txt_httpproxyuid);
  98. @@ -815,7 +819,6 @@
  99.              this.groupBox2.Controls.Add(this.label20);
  100.              this.groupBox2.Controls.Add(this.label19);
  101.              this.groupBox2.Controls.Add(this.label18);
  102. -            this.groupBox2.Controls.Add(this.cbx_usehttpproxy);
  103.              this.groupBox2.Location = new System.Drawing.Point(227, 234);
  104.              this.groupBox2.Name = "groupBox2";
  105.              this.groupBox2.Size = new System.Drawing.Size(240, 144);
  106. @@ -823,6 +826,30 @@
  107.              this.groupBox2.TabStop = false;
  108.              this.groupBox2.Text = " Auto Update Http Proxy ";
  109.              //
  110. +            // label1
  111. +            //
  112. +            this.label1.AutoSize = true;
  113. +            this.label1.Location = new System.Drawing.Point(7, 19);
  114. +            this.label1.Name = "label1";
  115. +            this.label1.Size = new System.Drawing.Size(35, 13);
  116. +            this.label1.TabIndex = 10;
  117. +            this.label1.Text = "Use:";
  118. +            //
  119. +            // cbHttpProxyMode
  120. +            //
  121. +            this.cbHttpProxyMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  122. +            this.cbHttpProxyMode.FormattingEnabled = true;
  123. +            this.cbHttpProxyMode.Items.AddRange(new object[] {
  124. +            "None",
  125. +            "System Proxy",
  126. +            "Custom Proxy",
  127. +            "Custom Proxy With Login"});
  128. +            this.cbHttpProxyMode.Location = new System.Drawing.Point(55, 16);
  129. +            this.cbHttpProxyMode.Name = "cbHttpProxyMode";
  130. +            this.cbHttpProxyMode.Size = new System.Drawing.Size(179, 21);
  131. +            this.cbHttpProxyMode.TabIndex = 9;
  132. +            this.cbHttpProxyMode.SelectedIndexChanged += new System.EventHandler(this.cbHttpProxyMode_SelectedIndexChanged);
  133. +            //
  134.              // txt_httpproxyport
  135.              //
  136.              this.txt_httpproxyport.Enabled = false;
  137. @@ -892,17 +919,6 @@
  138.              this.label18.TabIndex = 1;
  139.              this.label18.Text = "Server:";
  140.              //
  141. -            // cbx_usehttpproxy
  142. -            //
  143. -            this.cbx_usehttpproxy.AutoSize = true;
  144. -            this.cbx_usehttpproxy.Location = new System.Drawing.Point(9, 21);
  145. -            this.cbx_usehttpproxy.Name = "cbx_usehttpproxy";
  146. -            this.cbx_usehttpproxy.Size = new System.Drawing.Size(75, 17);
  147. -            this.cbx_usehttpproxy.TabIndex = 0;
  148. -            this.cbx_usehttpproxy.Text = "Use Proxy";
  149. -            this.cbx_usehttpproxy.UseVisualStyleBackColor = true;
  150. -            this.cbx_usehttpproxy.CheckedChanged += new System.EventHandler(this.cbx_usehttpproxy_CheckedChanged);
  151. -            //
  152.              // gbVideoPreview
  153.              //
  154.              this.gbVideoPreview.Controls.Add(this.chkEnsureCorrectPlaybackSpeed);
  155. @@ -1589,12 +1605,14 @@
  156.              }
  157.          }
  158.  
  159. -        private void cbx_usehttpproxy_CheckedChanged(object sender, EventArgs e)
  160. +        private void cbHttpProxyMode_SelectedIndexChanged(object sender, EventArgs e)
  161.          {
  162. -            txt_httpproxyaddress.Enabled = cbx_usehttpproxy.Checked;
  163. -            txt_httpproxyport.Enabled = cbx_usehttpproxy.Checked;
  164. -            txt_httpproxyuid.Enabled = cbx_usehttpproxy.Checked;
  165. -            txt_httpproxypwd.Enabled = cbx_usehttpproxy.Checked;
  166. +            var httpProxyMode = (ProxyMode)this.cbHttpProxyMode.SelectedIndex;
  167. +
  168. +            txt_httpproxyaddress.Enabled = httpProxyMode == ProxyMode.CustomProxy || httpProxyMode == ProxyMode.CustomProxyWithLogin;
  169. +            txt_httpproxyport.Enabled = httpProxyMode == ProxyMode.CustomProxy || httpProxyMode == ProxyMode.CustomProxyWithLogin;
  170. +            txt_httpproxyuid.Enabled = httpProxyMode == ProxyMode.CustomProxyWithLogin;
  171. +            txt_httpproxypwd.Enabled = httpProxyMode == ProxyMode.CustomProxyWithLogin;
  172.          }
  173.  
  174.          private void clearDefaultOutputDir_Click(object sender, EventArgs e)
  175. @@ -1655,7 +1673,7 @@
  176.                  settings.AutoSelectHDStreams = chkSelectHDTracks.Checked;
  177.                  settings.AedSettings = this.autoEncodeDefaults;
  178.                  settings.AlwaysOnTop = chAlwaysOnTop.Checked;
  179. -                settings.UseHttpProxy = cbx_usehttpproxy.Checked;
  180. +                settings.HttpProxyMode = (ProxyMode)this.cbHttpProxyMode.SelectedIndex;
  181.                  settings.HttpProxyAddress = txt_httpproxyaddress.Text;
  182.                  settings.HttpProxyPort = txt_httpproxyport.Text;
  183.                  settings.HttpProxyUid = txt_httpproxyuid.Text;
  184. @@ -1721,7 +1739,7 @@
  185.                  chkSelectHDTracks.Checked = settings.AutoSelectHDStreams;
  186.                  this.autoEncodeDefaults = settings.AedSettings;
  187.                  chAlwaysOnTop.Checked = settings.AlwaysOnTop;
  188. -                cbx_usehttpproxy.Checked = settings.UseHttpProxy;
  189. +                cbHttpProxyMode.SelectedIndex = (int)settings.HttpProxyMode;
  190.                  txt_httpproxyaddress.Text = settings.HttpProxyAddress;
  191.                  txt_httpproxyport.Text = settings.HttpProxyPort;
  192.                  txt_httpproxyuid.Text = settings.HttpProxyUid;
  193. Index: core/gui/UpdateCacher.cs
  194. ===================================================================
  195. --- core/gui/UpdateCacher.cs    (revision 2258)
  196. +++ core/gui/UpdateCacher.cs    (working copy)
  197. @@ -135,26 +135,8 @@
  198.              WebClient wc = new WebClient();
  199.  
  200.              // check for proxy authentication...
  201. -            if (MainForm.Instance.Settings.UseHttpProxy == true)
  202. -            {
  203. -                WebProxy wprox = null;
  204. -                ICredentials icred = null;
  205. +            wc.Proxy = HttpProxy.GetProxy(MainForm.Instance.Settings);
  206.  
  207. -                if (MainForm.Instance.Settings.HttpProxyUid != null)
  208. -                {
  209. -                    icred = new NetworkCredential(MainForm.Instance.Settings.HttpProxyUid, MainForm.Instance.Settings.HttpProxyPwd);
  210. -                }
  211. -
  212. -                wprox = new WebProxy(MainForm.Instance.Settings.HttpProxyAddress + ":" + MainForm.Instance.Settings.HttpProxyPort, true, null, icred);
  213. -
  214. -                WebRequest.DefaultWebProxy = wprox;
  215. -                wc.Proxy = wprox;
  216. -            }
  217. -            else
  218. -            {
  219. -                wc.Proxy = null;
  220. -            }
  221. -
  222.              ManualResetEvent mre = new ManualResetEvent(false);
  223.              wc.DownloadFileCompleted += delegate(object sender, AsyncCompletedEventArgs e)
  224.              {
  225. Index: core/gui/UpdateWindow.cs
  226. ===================================================================
  227. --- core/gui/UpdateWindow.cs    (revision 2258)
  228. +++ core/gui/UpdateWindow.cs    (working copy)
  229. @@ -1265,18 +1265,7 @@
  230.                  WebClient serverClient = new WebClient();
  231.  
  232.                  // check for proxy authentication...
  233. -                if (meGUISettings.UseHttpProxy && !String.IsNullOrEmpty(meGUISettings.HttpProxyAddress))
  234. -                {
  235. -                    WebProxy wprox = null;
  236. -                    ICredentials icred = null;
  237. -                    if (meGUISettings.HttpProxyUid != null)
  238. -                        icred = new NetworkCredential(meGUISettings.HttpProxyUid, meGUISettings.HttpProxyPwd);
  239. -                    wprox = new WebProxy(meGUISettings.HttpProxyAddress + ":" + meGUISettings.HttpProxyPort, true, null, icred);
  240. -                    WebRequest.DefaultWebProxy = wprox;
  241. -                    serverClient.Proxy = wprox;
  242. -                }
  243. -                else
  244. -                    serverClient.Proxy = null;
  245. +                serverClient.Proxy = HttpProxy.GetProxy(meGUISettings);
  246.                  
  247.                  try
  248.                  {
  249. Index: MeGUI.csproj
  250. ===================================================================
  251. --- MeGUI.csproj    (revision 2258)
  252. +++ MeGUI.csproj    (working copy)
  253. @@ -498,6 +498,7 @@
  254.      <Compile Include="core\util\FileUtil.cs" />
  255.      <Compile Include="core\util\FilmCutter.cs" />
  256.      <Compile Include="core\util\GenericRegisterer.cs" />
  257. +    <Compile Include="core\util\HttpProxy.cs" />
  258.      <Compile Include="core\util\IFOparser.cs" />
  259.      <Compile Include="core\util\JobUtil.cs" />
  260.      <Compile Include="core\util\LanguageSelectionContainer.cs" />
  261. Index: core/util/HttpProxy.cs
  262. ===================================================================
  263. --- core/util/HttpProxy.cs  (revision 0)
  264. +++ core/util/HttpProxy.cs  (working copy)
  265. @@ -0,0 +1,55 @@
  266. +namespace MeGUI.core.util
  267. +{
  268. +    using System;
  269. +    using System.Net;
  270. +
  271. +    internal class HttpProxy
  272. +    {
  273. +        #region Public Methods and Operators
  274. +
  275. +        public static IWebProxy GetProxy(MeGUISettings settings)
  276. +        {
  277. +            // if None then return null
  278. +            if (settings.HttpProxyMode == ProxyMode.None)
  279. +            {
  280. +                return null;
  281. +            }
  282. +
  283. +            // if SystemProxy then return the System proxy details with the logged in credentials
  284. +            if (settings.HttpProxyMode == ProxyMode.SystemProxy)
  285. +            {
  286. +                var systemProxy = WebRequest.GetSystemWebProxy();
  287. +                systemProxy.Credentials = CredentialCache.DefaultCredentials;
  288. +                return systemProxy;
  289. +            }
  290. +
  291. +            // CustomProxy and CustomProxyWithLogin both require a Url
  292. +            if (String.IsNullOrEmpty(settings.HttpProxyAddress))
  293. +            {
  294. +                return null;
  295. +            }
  296. +
  297. +            var address = string.IsNullOrEmpty(settings.HttpProxyPort)
  298. +                              ? settings.HttpProxyAddress
  299. +                              : string.Format("{0}:{1}", settings.HttpProxyAddress, settings.HttpProxyPort);
  300. +
  301. +            // if CustomProxyWithLogin then generate the credentials
  302. +            ICredentials credentials;
  303. +
  304. +            if (settings.HttpProxyMode == ProxyMode.CustomProxy || string.IsNullOrEmpty(settings.HttpProxyUid))
  305. +            {
  306. +                credentials = null;
  307. +            }
  308. +            else
  309. +            {
  310. +                credentials = new NetworkCredential(settings.HttpProxyUid, settings.HttpProxyPwd);
  311. +            }
  312. +
  313. +            var proxy = new WebProxy(address, true, null, credentials);
  314. +
  315. +            return proxy;
  316. +        }
  317. +
  318. +        #endregion
  319. +    }
  320. +}
  321. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement