Skip to content

Instantly share code, notes, and snippets.

@alecnunn
Last active August 29, 2015 14:22
Show Gist options
  • Select an option

  • Save alecnunn/ad926965834b17fa431a to your computer and use it in GitHub Desktop.

Select an option

Save alecnunn/ad926965834b17fa431a to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Text.RegularExpressions;
using System.IO;
namespace SVN_Archiver {
class Program {
static void Main(string[] args) {
string line;
System.IO.StreamReader file = new System.IO.StreamReader(args[0]);
while ((line = file.ReadLine()) != null) {
//"http://sourceforge.net/p/a-bot/code/HEAD/tree/"
string url = string.Format("http://sourceforge.net/p/{0}/code", line.Split('/')[4]);
WebClient wc = new WebClient();
try {
string contents = wc.DownloadString(url);
Regex r = new Regex("\"btn\" data-url=\"(.*)\"");
Match m = r.Match(contents);
string dl = m.Groups[1].Value.Replace("\" title=\"Read Only", "");
System.Diagnostics.Debug.WriteLine(dl);
PrintInfo(string.Format(dl));
try {
Console.WriteLine(dl);
LaunchCmd(dl);
PrintSuccess("Downloaded!");
} catch (Exception ex) {
using (StreamWriter w = File.AppendText("download_errors.txt")) {
Log(string.Format("Failed to download: {0}", dl), w);
}
PrintFail("Failed to download!");
}
} catch(Exception ex) {
PrintFail("Failed to get contents");
using (StreamWriter w = File.AppendText("parsing_errors.txt")) {
Log(string.Format("Failed to parse: {0}", line), w);
}
}
}
file.Close();
Console.ReadLine();
}
public static void PrintInfo(string info) {
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("[-] ");
Console.ResetColor();
Console.WriteLine(info);
}
public static void PrintSuccess(string info) {
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[+] ");
Console.ResetColor();
Console.WriteLine(info);
}
public static void PrintWarning(string info) {
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("[!] ");
Console.ResetColor();
Console.WriteLine(info);
}
public static void PrintFail(string info) {
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("[x] ");
Console.ResetColor();
Console.WriteLine(info);
}
public static void LaunchCmd(string url) {
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
string[] parts = url.Split(' ');
switch (parts[0]) {
case "svn":
startInfo.FileName = "svn.exe";
break;
case "hg":
startInfo.FileName = "hg.exe";
break;
case "git":
startInfo.FileName = "git.exe";
break;
default:
startInfo.FileName = "svn.exe";
break;
}
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = false;
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.Arguments = string.Join(" ", parts.Skip(1));
try {
using (System.Diagnostics.Process p = System.Diagnostics.Process.Start(startInfo)) {
p.WaitForExit();
}
} catch {
PrintFail("Failed to download!");
}
}
public static void Log(string msg, TextWriter w) {
w.WriteLine(string.Format("{0}", msg));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment