mirror of
https://github.com/SabreTools/MPF.git
synced 2026-02-14 05:36:10 +00:00
* Who doesn't like drives? * Add another TODO * Use built in stuff, it's quicker * More special handling for floppies, easier this time * Fix broken test * Set active drive priority, String -> string * Track reason for no scanning * Update DIC version and release notes
37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
using System;
|
|
using System.Net;
|
|
|
|
namespace DICUI.Web
|
|
{
|
|
// https://stackoverflow.com/questions/1777221/using-cookiecontainer-with-webclient-class
|
|
public class CookieAwareWebClient : WebClient
|
|
{
|
|
private readonly CookieContainer m_container = new CookieContainer();
|
|
|
|
protected override WebRequest GetWebRequest(Uri address)
|
|
{
|
|
WebRequest request = base.GetWebRequest(address);
|
|
HttpWebRequest webRequest = request as HttpWebRequest;
|
|
if (webRequest != null)
|
|
{
|
|
webRequest.CookieContainer = m_container;
|
|
}
|
|
|
|
return request;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the last downloaded filename, if possible
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public string GetLastFilename()
|
|
{
|
|
// Try to extract the filename from the Content-Disposition header
|
|
if (!string.IsNullOrEmpty(this.ResponseHeaders["Content-Disposition"]))
|
|
return this.ResponseHeaders["Content-Disposition"].Substring(this.ResponseHeaders["Content-Disposition"].IndexOf("filename=") + 9).Replace("\"", "");
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|