public bool Update(int i) { bool ok = false; try { var sua = new SvnUpdateArgs { Revision = new SvnRevision(i) }; events(); ok = SC.CleanUp(GetAppLoc()); ok = SC.Update(GetAppLoc(), sua); } catch(Exception ex) { ShowInfo("更新时遇到问题:" + ex.Message + "\r\n"); WriteError(ex); } ShowInfo("更新完成...."); return ok; }
private LoadSourcesResult LoadSourcesWithUpdate(SourceControlVersion sourceControlVersion, string path, SvnClient client) { SvnUpdateResult result; try { client.Update(path, out result); } catch (SvnInvalidNodeKindException e) { Directory.Delete(path, true); return(this.LoadSourcesFromScratch(sourceControlVersion, path, client)); } catch (SvnWorkingCopyException e) { client.CleanUp(path); client.Update(path, out result); } SvnInfoEventArgs info; client.GetInfo(path, out info); return(new LoadSourcesResult { RevisionId = info.LastChangeRevision.ToString(CultureInfo.InvariantCulture) }); }
private void GetHistory() { if (reversedFileversion != null) { return; } using (SvnClient client = new SvnClient()) { client.CleanUp(Path.GetDirectoryName(_excelFilePath)); Collection <SvnFileVersionEventArgs> fileVersions = new Collection <SvnFileVersionEventArgs>(); var tt = new SvnFileVersionsArgs(); tt.Start = new SvnRevision(DateTime.Now.AddDays(-1)); tt.End = new SvnRevision(DateTime.Now); client.GetFileVersions( new SvnPathTarget(_excelFilePath, DateTime.Now), new SvnFileVersionsArgs(), out fileVersions); reversedFileversion = fileVersions.Reverse(); reversedFileversion = reversedFileversion.OrderByDescending(x => x.Revision); } }
private void dlModWorker_DoWork(object sender, DoWorkEventArgs e) { SvnClient client = new SvnClient(); string[] args = (string[])e.Argument; string remLocation = args[0]; string locLocation = args[1]; remLocation = remLocation.Replace(System.IO.Path.GetFileName(new Uri(remLocation).LocalPath), ""); locLocation = Path.GetDirectoryName(locLocation); Debug.WriteLine(remLocation + " && " + locLocation); BackgroundWorker worker = sender as BackgroundWorker; if (Directory.Exists(locLocation)) { Directory.Delete(locLocation, true); } Directory.CreateDirectory(locLocation); if (Directory.Exists(Path.Combine(locLocation, ".svn"))) { client.CleanUp(locLocation); } client.CheckOut(new Uri(remLocation), locLocation); fexeProcessDirectory(locLocation); // aka the "thanks a lot, flatgrass" function }
public void Cleanup_Basic() { SvnSandBox sbox = new SvnSandBox(this); sbox.Create(SandBoxRepository.Default); using (SvnClient client = NewSvnClient(false, false)) { client.CleanUp(sbox.Wc); } }
private void TryCleanUp() { try { if (System.IO.Directory.Exists(LocalPath)) { _SvnClient.CleanUp(LocalPath); } } catch { } }
public void Cleanup(string workingPath) { try { client.CleanUp(workingPath); } catch (Exception ex) { OnError(ex); } }
internal void CheckOut(SvnClient client, SvnUriTarget url, string path, SvnCheckOutArgs args, bool cleanUpWhenLocked) { try { bool foundLockException = false; int cleanupCount = 0; do { try { foundLockException = false; if (args != null) { client.CheckOut(url, path, args); } else { client.CheckOut(url, path); } } catch (SvnException ex) { foundLockException = true; if ((ex.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_CLEANUP_REQUIRED || ex.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_LOCKED || ex.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_DB_ERROR || ex.SvnErrorCode == SvnErrorCode.SVN_ERR_SQLITE_BUSY) && cleanUpWhenLocked) { client.CleanUp(path, new SvnCleanUpArgs() { ClearDavCache = true, BreakLocks = true, IncludeExternals = true, }); cleanupCount++; } else { throw; } if (cleanupCount >= 5) { throw new Exception("Cleanup was done 5 time. So we decided to stop it. You can try Checking out again."); } } } while (foundLockException && cleanUpWhenLocked); } catch (Exception) { throw; } }
public static void Update(ConfigRepository repository, Log log, string directory) { if (!repository.Enabled) { Utility.Log(LogStatus.Skipped, string.Format("Disabled - {0}", repository.Url), log); } else if (string.IsNullOrWhiteSpace(repository.Url)) { Utility.Log(LogStatus.Skipped, string.Format("No Url specified - {0}", repository.Url), log); } else { try { string dir = Path.Combine(directory, repository.Url.GetHashCode().ToString("X")); using (var client = new SvnClient()) { bool cleanUp = false; client.Conflict += delegate(object sender, SvnConflictEventArgs eventArgs) { eventArgs.Choice = SvnAccept.TheirsFull; }; client.Status(dir, new SvnStatusArgs { ThrowOnError = false }, delegate(object sender, SvnStatusEventArgs args) { if (args.Wedged) { cleanUp = true; } }); if (cleanUp) { client.CleanUp(dir); } client.CheckOut(new Uri(repository.Url), dir); client.Update(dir); Utility.Log(LogStatus.Ok, string.Format("Updated - {0}", repository.Url), log); } } catch (SvnException ex) { Utility.Log(LogStatus.Error, string.Format("{0} - {1}", ex.RootCause, repository.Url), log); } catch (Exception ex) { Utility.Log(LogStatus.Error, string.Format("{0} - {1}", ex.Message, repository.Url), log); } } }
public override void CleanUp(string Path) { if (client == null) { Init(); } try { client.CleanUp(Path); } catch (Exception e) { } }
private void SvnUpdate(bool isMandatory, string[] targetDirs) { string workingCopyPath = ConfigurationManager.AppSettings["WorkingCopy.Path"]; string svnUsername = ConfigurationManager.AppSettings["Svn.Username"]; string svnPassword = ConfigurationManager.AppSettings["Svn.Password"]; using (SvnClient client = new SvnClient()) { client.Authentication.ForceCredentials(svnUsername, svnPassword); client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "sharpsvn"), true); SvnPathTarget local = new SvnPathTarget(workingCopyPath); SvnInfoEventArgs clientInfo; client.GetInfo(local, out clientInfo); SvnLockInfo lockInfo = clientInfo.Lock; if (lockInfo != null) { client.CleanUp(workingCopyPath); lockInfo = clientInfo.Lock; if (lockInfo != null) { client.Unlock(workingCopyPath); } } SvnUpdateArgs updateArgs = new SvnUpdateArgs(); updateArgs.AllowObstructions = false; updateArgs.Depth = SvnDepth.Infinity; updateArgs.IgnoreExternals = false; updateArgs.UpdateParents = true; updateArgs.Revision = SvnRevision.Head; updateArgs.Conflict += new EventHandler <SvnConflictEventArgs>(UpdateArgs_Conflict); foreach (string targetDir in targetDirs) { string localPath = workingCopyPath + targetDir; if (isMandatory) { ClearFiles(client, localPath, targetDir, 0); } foreach (string file in Directory.GetFiles(localPath, "*.css")) { File.Delete(file); } client.Update(localPath, updateArgs); } } }
public override void CleanUp(string Path) { if (client == null) { Init(); } try { client.CleanUp(Path); } catch (Exception e) { Reporter.ToLog(eLogLevel.ERROR, $"Method - {MethodBase.GetCurrentMethod().Name}, Error - {e.Message}"); } }
public static string Update(string url, Log log, string directory) { if (string.IsNullOrWhiteSpace(url)) { Utility.Log(LogStatus.Skipped, "Updater", string.Format("No Url specified - {0}", url), log); } else { try { var dir = Path.Combine(directory, url.GetHashCode().ToString("X")); using (var client = new SvnClient()) { var cleanUp = false; client.Conflict += delegate(object sender, SvnConflictEventArgs eventArgs) { eventArgs.Choice = SvnAccept.TheirsFull; }; client.Status( dir, new SvnStatusArgs { ThrowOnError = false }, delegate(object sender, SvnStatusEventArgs args) { if (args.Wedged) { cleanUp = true; } }); if (cleanUp) { client.CleanUp(dir); } try { if (Directory.Exists(dir)) { SvnInfoEventArgs remoteVersion; var b1 = client.GetInfo(new Uri(url), out remoteVersion); SvnInfoEventArgs localVersion; var b2 = client.GetInfo(dir, out localVersion); if (b1 && b2 && remoteVersion.Revision == localVersion.Revision) { Utility.Log( LogStatus.Ok, "Updater", string.Format("Update not needed - {0}", url), log); return(dir); } } } catch (Exception ex) { Utility.Log(LogStatus.Error, "Updater", string.Format("{0} - {1}", ex, url), log); } client.CheckOut(new Uri(url), dir); client.Update(dir); Utility.Log(LogStatus.Ok, "Updater", string.Format("Updated - {0}", url), log); } return(dir); } catch (SvnException ex) { Utility.Log(LogStatus.Error, "Updater", string.Format("{0} - {1}", ex.RootCause, url), log); } catch (Exception ex) { Utility.Log(LogStatus.Error, "Updater", string.Format("{0} - {1}", ex.Message, url), log); } } return(string.Empty); }
public static bool SvnCleanup(string path) { SvnClient client = new SvnClient(); return client.CleanUp(path); }
/// <summary> /// Actual method to be executed for the implementing task /// </summary> /// <param name="client">The instance of the SVN client</param> /// <returns></returns> public override bool ExecuteCommand(SvnClient client) { return client.CleanUp(RepositoryPath); }
/// <summary> /// svn代码获取 /// </summary> /// <param name="svnuri">svn地址</param> static void SVNUpdate(string svnuri, out string logmessage, out long reversion) { logmessage = ""; reversion = 0; using (SvnClient client = new SvnClient()) { var localpath = "d:\\sharpsvn"; localpath = @"E:\project\ccms\CCMS_V7_HBYD_R"; var username = ""; var pwd = ""; client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(username, pwd); //如果项目不存在则checkout,否则进行update if (!Directory.Exists(localpath)) { client.CheckOut(new Uri(svnuri), localpath); // Console.WriteLine("svn checkout success"); } else { SvnInfoEventArgs serverInfo; SvnInfoEventArgs clientInfo; SvnUriTarget repos = new SvnUriTarget(svnuri); SvnPathTarget local = new SvnPathTarget(localpath); SvnUpdateArgs args = new SvnUpdateArgs(); args.Depth = SvnDepth.Infinity; var svnService = new SvnService(); long version = 0; long clientVersion = -1; var msg = ""; args.Notify += delegate(object sender, SvnNotifyEventArgs e) { //if (svnService.GetNotifyAction(e.Action) == "添加") //{ // msg += "\r\n添加" + e.FullPath; //} //if (svnService.GetNotifyAction(e.Action) == "更新删除") //{ // msg += "\r\n删除:" + e.FullPath; //} //if (svnService.GetNotifyAction(e.Action) == "更新修改") //{ // msg += "\r\n修改" + e.FullPath; //} msg += "\r\n" + (svnService.GetNotifyAction(e.Action)) + ":" + e.FullPath; version = e.Revision; }; client.GetInfo(repos, out serverInfo); client.GetInfo(local, out clientInfo); clientVersion = clientInfo.Revision; //if (clientVersion < version)//客户端version必须小于服务端才更新 //{ client.CleanUp(localpath); SvnRevertArgs args2 = new SvnRevertArgs() { Depth = SvnDepth.Infinity }; client.Revert(localpath, args2); client.Update(localpath, args); //获取消息 Collection <SvnLogEventArgs> logitems; //if (version > 0 && clientVersion < version) if (msg.Length > 5) { reversion = version; logmessage += "\r\n变更文件:" + msg; client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(clientVersion + 1, version)), out logitems); // client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(version, version)), out logitems); foreach (var logentry in logitems) { string author = logentry.Author; string message = logentry.LogMessage; //DateTime checkindate = logentry.Time; logmessage += "\r\n"; logmessage += string.Format("提交人:{0} ,日志: {1}", author, message) + "\r\n"; } } //} // Console.WriteLine(string.Format("serverInfo revision of {0} is {1}", repos, serverInfo.Revision)); //Console.WriteLine(string.Format("clientInfo revision of {0} is {1}", local, clientInfo.Revision)); // Console.WriteLine("代码获取成功"); } }// }
private void UpdateButtonClick(object sender, EventArgs e) { UpdateButton.Enabled = false; UpdateButton.Text = Resources.updateButtonUpdating; // Check if user has selected any addons in the list. if not update all if (listAddonsList.SelectedItems.Count != 0) { foreach (ListViewItem item in listAddonsList.SelectedItems) { var addonDir = _installDir + "\\" + item.Text; if (Directory.Exists(addonDir + "\\.svn")) { try { var svnClient = new SvnClient(); svnClient.Update(addonDir); } catch (SvnWorkingCopyLockException) { var svnClient = new SvnClient(); svnClient.CleanUp(addonDir); svnClient.Update(addonDir); throw; } } else if (Directory.Exists(addonDir + "\\.git") && Environment.ExpandEnvironmentVariables("path").IndexOf("git") != 0) { var processInfo = new ProcessStartInfo("git") {WorkingDirectory = addonDir, Arguments = "fetch"}; var process = Process.Start(processInfo); process.WaitForExit(); process.StartInfo.Arguments = "merge origin/master"; process.Start(); } } } else { // Update all repositories in a nice threaded way Parallel.ForEach(Directory.GetDirectories(_installDir), dir => { // Check if the addon is updated by SVN if (Directory.Exists(dir + "\\.svn")) { try { var svnClient = new SvnClient(); svnClient.Update(dir); } catch (SvnWorkingCopyLockException) { var svnClient = new SvnClient(); svnClient.CleanUp(dir); svnClient.Update(dir); throw; } } // Check if there are any git addons and if the user has git installed and if both are true then "update" the addons else if (Directory.Exists(dir + "\\.git") && Environment.ExpandEnvironmentVariables("path").IndexOf("git") != 0) { var processInfo = new ProcessStartInfo("git") {WorkingDirectory = dir, Arguments = "fetch"}; var process = Process.Start(processInfo); process.WaitForExit(); process.StartInfo.Arguments = "merge origin/master"; process.Start(); } }); MessageBox.Show(Resources.updateCompleteMessage, Resources.updateCompleteHeader); } UpdateButton.Text = Resources.updateButDefaultText; UpdateButton.Enabled = true; }
public static string Update(string url, Log log, string directory) { if (string.IsNullOrWhiteSpace(url)) { Utility.Log(LogStatus.Skipped, "Updater", string.Format("No Url specified - {0}", url), log); } else { try { var dir = Path.Combine(directory, url.GetHashCode().ToString("X")); using (var client = new SvnClient()) { var cleanUp = false; client.Conflict += delegate(object sender, SvnConflictEventArgs eventArgs) { eventArgs.Choice = SvnAccept.TheirsFull; }; client.Status( dir, new SvnStatusArgs { ThrowOnError = false }, delegate(object sender, SvnStatusEventArgs args) { if (args.Wedged) { cleanUp = true; } }); if (cleanUp) { client.CleanUp(dir); } try { if (Directory.Exists(dir)) { SvnInfoEventArgs remoteVersion; var b1 = client.GetInfo(new Uri(url), out remoteVersion); SvnInfoEventArgs localVersion; var b2 = client.GetInfo(dir, out localVersion); if (b1 && b2 && remoteVersion.Revision == localVersion.Revision) { Utility.Log( LogStatus.Ok, "Updater", string.Format("Update not needed - {0}", url), log); return dir; } } } catch (Exception ex) { Utility.Log(LogStatus.Error, "Updater", string.Format("{0} - {1}", ex, url), log); } client.CheckOut(new Uri(url), dir); client.Update(dir); Utility.Log(LogStatus.Ok, "Updater", string.Format("Updated - {0}", url), log); } return dir; } catch (SvnException ex) { Utility.Log(LogStatus.Error, "Updater", string.Format("{0} - {1}", ex.RootCause, url), log); } catch (Exception ex) { Utility.Log(LogStatus.Error, "Updater", string.Format("{0} - {1}", ex.Message, url), log); } } return string.Empty; }
public void CleanUp(string SvnPathTarget) { client.CleanUp(SvnPathTarget); }
// 清理SVN public static void CleanSvn(string path) { SvnClient client = new SvnClient(); client.CleanUp(path); }
static int Main(string[] args) { try { Console.WriteLine("Svn2: {0}", Assembly.GetExecutingAssembly().GetName().Version); if (args.Length < 1) { Usage(); return(-2); } string command = args[0]; if (command == "/?" || command == "-?" || command == "--help") { Usage(); return(-2); } string path = (args.Length == 2) ? Path.GetFullPath(args[1]) : Path.GetFullPath(Environment.CurrentDirectory); SvnClient client = new SvnClient(); switch (command) { case "sync": { SvnStatusArgs statusArgs = new SvnStatusArgs(); statusArgs.Depth = SvnDepth.Infinity; statusArgs.ThrowOnError = true; client.Status(path, statusArgs, new EventHandler <SvnStatusEventArgs>(delegate(object sender, SvnStatusEventArgs e) { switch (e.LocalContentStatus) { case SvnStatus.NotVersioned: Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath); if (File.Exists(e.FullPath)) { FileSystem.DeleteFile(e.FullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } else if (Directory.Exists(e.FullPath)) { FileSystem.DeleteDirectory(e.FullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } break; } })); } break; case "cleanup": { Console.WriteLine("Cleaning up {0}", path); SvnCleanUpArgs cleanupArgs = new SvnCleanUpArgs(); cleanupArgs.ThrowOnError = true; cleanupArgs.Notify += new EventHandler <SvnNotifyEventArgs>(delegate(object sender, SvnNotifyEventArgs e) { Console.WriteLine(" L {0}", e.FullPath); }); client.CleanUp(path, cleanupArgs); } break; case "revert": { Console.WriteLine("Reverting {0}", path); SvnRevertArgs revertArgs = new SvnRevertArgs(); revertArgs.Depth = SvnDepth.Infinity; revertArgs.ThrowOnError = true; revertArgs.Notify += new EventHandler <SvnNotifyEventArgs>(delegate(object sender, SvnNotifyEventArgs e) { Console.WriteLine(" R {0}", e.FullPath); }); client.Revert(path, revertArgs); } break; case "status": { SvnStatusArgs statusArgs = new SvnStatusArgs(); statusArgs.Depth = SvnDepth.Infinity; statusArgs.ThrowOnError = true; client.Status(path, statusArgs, new EventHandler <SvnStatusEventArgs>(delegate(object sender, SvnStatusEventArgs e) { Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath); })); } break; default: throw new Exception(string.Format("Unsupported '{0}' command", command)); } return(0); } catch (Exception ex) { Console.Error.WriteLine(ex.Message); #if DEBUG Console.Error.WriteLine(ex.StackTrace); #endif return(-1); } }
/// <summary> /// 清理SVN /// </summary> /// <param name="path"></param> public void CleanSvn(string path) { _client.CleanUp(path); }
public static bool SvnCleanup(string path) { SvnClient client = new SvnClient(); return(client.CleanUp(path)); }
/// <summary> /// svn代码获取 /// </summary> /// <param name="svnuri">svn地址</param> static void SVNUpdate(string svnuri, out string logmessage, out long reversion) { logmessage = ""; reversion = 0; long clientVersion = -1; using (SvnClient client = new SvnClient()) { try { var localpath = WorkPath + @"\" + ProjCode + @"\" + BranchName; var username = ConfigHelper.GetValue("SVNUser"); var pwd = ConfigHelper.GetValue("SVNpwd"); client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(username, pwd); //notiny = "正在检查本地版本..."; //ShowInfo(); //SvnInfoEventArgs clientInfo; //bool okc = SC.GetInfo(local, out clientInfo); //if (oks && okc) //如果客户端服务端都会成功, 则对比服务器版本, 否则返回true 执行更新命令 //{ // result = (serverInfo.Revision > clientInfo.Revision); //} //如果项目不存在则checkout,否则进行update if (!Directory.Exists(localpath)) { client.CheckOut(new Uri(svnuri), localpath); Console.WriteLine("svn checkout success"); } else { SvnInfoEventArgs serverInfo; SvnInfoEventArgs clientInfo; SvnUriTarget repos = new SvnUriTarget(svnuri); SvnPathTarget local = new SvnPathTarget(localpath); SvnUpdateArgs args = new SvnUpdateArgs(); args.Depth = SvnDepth.Infinity; var svnService = new SvnService(); long version = 0; var msg = ""; args.Notify += delegate(object sender, SvnNotifyEventArgs e) { //if (svnService.GetNotifyAction(e.Action) == "添加") //{ // msg += "\r\n添加" + e.FullPath; //} //if (svnService.GetNotifyAction(e.Action) == "更新删除") //{ // msg += "\r\n删除:" + e.FullPath; //} //if (svnService.GetNotifyAction(e.Action) == "更新修改") //{ // msg += "\r\n修改" + e.FullPath; //} msg += "\r\n" + (svnService.GetNotifyAction(e.Action)) + ":" + e.FullPath; version = e.Revision; Console.WriteLine(msg); }; client.GetInfo(repos, out serverInfo); client.GetInfo(local, out clientInfo); clientVersion = clientInfo.Revision; //if (clientVersion < version)//客户端version必须小于服务端才更新 //{ //client.Resolve(localpath, SvnAccept.Base);//解决冲突 ////解决冲突 //Collection<SvnStatusEventArgs> statuses; //client.GetStatus(localpath, out statuses); //foreach (var item in statuses) //{ // if (item.Conflicted) // { // client.Resolve(item.FullPath, SvnAccept.Working); // Console.WriteLine("处理冲突文件:" + item.FullPath); // logmessage += "处理冲突文件:" + item.FullPath; // } //} client.CleanUp(localpath); SvnRevertArgs revertArgs = new SvnRevertArgs() { Depth = SvnDepth.Infinity }; //撤销本地所做的修改 client.Revert(localpath, revertArgs); client.Update(localpath, args); //获取消息 Collection <SvnLogEventArgs> logitems; //if (version > 0 && clientVersion < version) logmessage += "变更文件:" + msg; if (version > 0 && clientVersion < version) { reversion = version; client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(clientVersion + 1, version)), out logitems); //client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(version, version)), out logitems); foreach (var logentry in logitems) { string author = logentry.Author; string message = logentry.LogMessage; //DateTime checkindate = logentry.Time; logmessage += string.Format("\r\n提交人:{0} ,日志: {1}", author, message); } } //} } } catch (Exception ex) { Logger.Error(ex); logmessage = ex.ToString(); } } }
public static void CheckoutUpdate(Parameters parameters) { using var client = new SvnClient(); client.Progress += new EventHandler <SvnProgressEventArgs>(Client_Progress); SetUpClient(parameters, client); var target = SvnTarget.FromString(parameters.Path); SvnInfoEventArgs svnInfoEventArgs; SvnUpdateResult svnUpdateResult; var nonExistentUrl = false; EventHandler <SvnErrorEventArgs> ignoreNonexistent = (o, eventArgs) => { nonExistentUrl = false; //if (eventArgs.Exception.SubversionErrorCode == 170000) if (eventArgs.Exception.Message.Contains("non-existent in revision")) { nonExistentUrl = true; eventArgs.Cancel = true; } }; if (client.GetWorkingCopyRoot(parameters.Path) == null) { client.SvnError += ignoreNonexistent; var getInfoSucceeded = client.GetInfo(SvnUriTarget.FromString(parameters.Url), out svnInfoEventArgs); client.SvnError -= ignoreNonexistent; if (!getInfoSucceeded) { if (nonExistentUrl) { Console.WriteLine("SVN info reported nonexistent URL; creating remote directory."); if (!client.RemoteCreateDirectory(new Uri(parameters.Url), new SvnCreateDirectoryArgs { CreateParents = true, LogMessage = parameters.Message })) { throw new Exception("Create directory failed on " + parameters.Url); } } else { throw new Exception("SVN info failed"); } } DebugMessage(parameters, "Checking out"); if (client.CheckOut(SvnUriTarget.FromString(parameters.Url), parameters.Path, out svnUpdateResult)) { DebugMessage(parameters, "Done"); Console.WriteLine("Checked out r" + svnUpdateResult.Revision); return; } throw new Exception("SVN checkout failed"); } if (!client.GetInfo(target, out svnInfoEventArgs)) { throw new Exception("SVN info failed"); } if (!UrlsMatch(svnInfoEventArgs.Uri.ToString(), parameters.Url)) { throw new Exception(string.Format("A different URL is already checked out ({0} != {1})", svnInfoEventArgs.Uri, parameters.Url)); } if (parameters.Cleanup) { DebugMessage(parameters, "Cleaning up"); client.CleanUp(parameters.Path); DebugMessage(parameters, "Done"); } if (parameters.Revert) { DebugMessage(parameters, "Reverting"); client.Revert(parameters.Path); DebugMessage(parameters, "Done"); } if (parameters.DeleteUnversioned) { DebugMessage(parameters, "Deleting unversioned files"); Collection <SvnStatusEventArgs> changedFiles; client.GetStatus(parameters.Path, out changedFiles); foreach (var changedFile in changedFiles) { if (changedFile.LocalContentStatus == SvnStatus.NotVersioned) { if (changedFile.NodeKind == SvnNodeKind.Directory) { DebugMessage(parameters, "NodeKind is directory for [" + changedFile.FullPath + "]"); } if ((File.GetAttributes(changedFile.FullPath) & FileAttributes.Directory) == FileAttributes.Directory) { DebugMessage(parameters, "Deleting directory [" + changedFile.FullPath + "] recursively!"); Directory.Delete(changedFile.FullPath, true); } else { DebugMessage(parameters, "Deleting file [" + changedFile.FullPath + "]"); File.Delete(changedFile.FullPath); } } } DebugMessage(parameters, "Done"); } DebugMessage(parameters, "Updating"); if (client.Update(parameters.Path, out svnUpdateResult)) { DebugMessage(parameters, "Done"); Console.WriteLine("Updated to r" + svnUpdateResult.Revision); return; } throw new Exception("SVN update failed"); }
static int Main(string[] args) { try { Console.WriteLine("Svn2: {0}", Assembly.GetExecutingAssembly().GetName().Version); if (args.Length < 1) { Usage(); return -2; } string command = args[0]; if (command == "/?" || command == "-?" || command == "--help") { Usage(); return -2; } string path = (args.Length == 2) ? Path.GetFullPath(args[1]) : Path.GetFullPath(Environment.CurrentDirectory); SvnClient client = new SvnClient(); switch (command) { case "sync": { SvnStatusArgs statusArgs = new SvnStatusArgs(); statusArgs.Depth = SvnDepth.Infinity; statusArgs.ThrowOnError = true; client.Status(path, statusArgs, new EventHandler<SvnStatusEventArgs>(delegate(object sender, SvnStatusEventArgs e) { switch (e.LocalContentStatus) { case SvnStatus.NotVersioned: Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath); if (File.Exists(e.FullPath)) { FileSystem.DeleteFile(e.FullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } else if (Directory.Exists(e.FullPath)) { FileSystem.DeleteDirectory(e.FullPath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } break; } })); } break; case "cleanup": { Console.WriteLine("Cleaning up {0}", path); SvnCleanUpArgs cleanupArgs = new SvnCleanUpArgs(); cleanupArgs.ThrowOnError = true; cleanupArgs.Notify += new EventHandler<SvnNotifyEventArgs>(delegate(object sender, SvnNotifyEventArgs e) { Console.WriteLine(" L {0}", e.FullPath); }); client.CleanUp(path, cleanupArgs); } break; case "revert": { Console.WriteLine("Reverting {0}", path); SvnRevertArgs revertArgs = new SvnRevertArgs(); revertArgs.Depth = SvnDepth.Infinity; revertArgs.ThrowOnError = true; revertArgs.Notify += new EventHandler<SvnNotifyEventArgs>(delegate(object sender, SvnNotifyEventArgs e) { Console.WriteLine(" R {0}", e.FullPath); }); client.Revert(path, revertArgs); } break; case "status": { SvnStatusArgs statusArgs = new SvnStatusArgs(); statusArgs.Depth = SvnDepth.Infinity; statusArgs.ThrowOnError = true; client.Status(path, statusArgs, new EventHandler<SvnStatusEventArgs>(delegate(object sender, SvnStatusEventArgs e) { Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath); })); } break; default: throw new Exception(string.Format("Unsupported '{0}' command", command)); } return 0; } catch (Exception ex) { Console.Error.WriteLine(ex.Message); #if DEBUG Console.Error.WriteLine(ex.StackTrace); #endif return -1; } }
private void dlModWorker(object sender, DoWorkEventArgs e) { List <Mod> checkedMods = new List <Mod>(); foreach (Mod listedMod in downloadableModsList.Items) { if (listedMod.IsChecked == true) { checkedMods.Add(listedMod); } } if (checkedMods.Count == 0) { return; } Dispatcher.Invoke(new Action(() => { modsTabs.IsEnabled = false; menu.IsEnabled = false; everythingGrid.Effect = new BlurEffect { Radius = 10 }; installLogGrid.Visibility = Visibility.Visible; closeLogButton.Visibility = Visibility.Collapsed; closeLogButton.Focus(); installLogBox.Text = ""; installLogBox.Text += "-- " + downloadingmods.ToUpper() + " --" + Environment.NewLine + Environment.NewLine; })); int i = 0; foreach (Mod checkedMod in checkedMods) { i++; Dispatcher.Invoke(new Action(() => { installLogBox.Text += downloadingmods + " (" + i + "/" + checkedMods.Count + ") : " + checkedMod.Name + " " + checkedMod.Version + Environment.NewLine; })); SvnClient svnClient = new SvnClient(); svnClient.Progress += new EventHandler <SvnProgressEventArgs>(svnProgress); string remoteLocation = repository + Path.GetDirectoryName(checkedMod.Location); string localLocation = Path.GetDirectoryName(Path.Combine(System.IO.Directory.GetCurrentDirectory(), "mods", "tagmods", checkedMod.Location.Replace("/", "\\"))); try { deleteDirectory(localLocation); } catch { // mod doesn't already exist - all fine } if (!Directory.Exists(localLocation)) { Directory.CreateDirectory(localLocation); } if (Directory.Exists(Path.Combine(localLocation, ".svn"))) { svnClient.CleanUp(localLocation); } try { svnClient.CheckOut(new Uri(remoteLocation), localLocation); Dispatcher.Invoke(new Action(() => { installLogBox.Text += "| " + moddlsuccess + Environment.NewLine; })); } catch { Dispatcher.Invoke(new Action(() => { installLogBox.Text += "| " + moddlfailed + Environment.NewLine; })); } } Dispatcher.Invoke(new Action(() => { MessageBox.Show(Application.Current.MainWindow, modsdownloaded, this.Title, MessageBoxButton.OK, MessageBoxImage.Information); closeLogButton.Visibility = Visibility.Visible; foreach (Mod listedMod in downloadableModsList.Items) { if (listedMod.IsChecked == true) { listedMod.IsChecked = false; } } mMods.Clear(); infobarScroll.Visibility = Visibility.Collapsed; workerPopulateMyMods.RunWorkerAsync(); })); }