Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string GetFilename(string url) {
- string filename = url.Substring(url.LastIndexOf("/") + 1);
- if(filename.Contains(".")) {
- string extension = filename.Substring(filename.LastIndexOf(".") + 1).ToLower();
- string[] blacklisted_extensions = new string[]
- {
- "exe",
- "msi",
- "msp",
- "msu",
- "p2"
- };
- for (int i = 0; i < blacklisted_extensions.Length; i++)
- {
- if (blacklisted_extensions[i] == extension)
- {
- throw new Exception("Blacklisted extension");
- }
- }
- bool found_whitelisted_extension = false;
- for (int i = 0; i < whitelisted_hashes.Length; i++)
- {
- if (whitelisted_hashes[i] == extension)
- {
- found_whitelisted_extension = true;
- break;
- }
- }
- if(!found_whitelisted_extension)
- throw new Exception("Invalid extension");
- }
- foreach (char oldChar in Path.GetInvalidFileNameChars())
- {
- filename = filename.Replace(oldChar, ' ');
- }
- return filename;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement