/// <summary> /// Saves the path. This method is called from <see cref="AdjustmentForm"/> /// when the user clicks the "OK" button. /// </summary> internal void Save() { // There SHOULD be a path to save. if (m_PathData == null) { MessageBox.Show("PathForm.Save -- nothing to save"); return; } // Ensure adjustment dialog has been destroyed. OnDestroyAdj(); // Execute the edit PathOperation op = null; try { string str = GetEnteredPath(); DistanceUnit defaultEntryUnit = EditingController.Current.EntryUnit; op = new PathOperation(m_From, m_To, str, defaultEntryUnit); op.Execute(); Finish(); } catch (Exception ex) { MessageBox.Show(ex.StackTrace, ex.Message); } }
/// <summary> /// 获取特定Mod信息 /// </summary> /// <param name="name">欲获取Mod的名称</param> /// <param name="shouldHave">应该存在,若为真则产生报错信息</param> /// <returns>返回ModInformation</returns> public ModInformation GetModInformation(string name, bool shouldHave) { try { XmlDocument xml = new XmlDocument(); xml.Load(PathOperation.GetModsIndexPath()); string time = xml.SelectSingleNode("mods/mod_" + name + "/time").InnerText; string size = xml.SelectSingleNode("mods/mod_" + name + "/size").InnerText; List <string> contain = new List <string>(); XmlNodeList fileNodes = xml.SelectNodes("mods/mod_" + name + "/files/file"); foreach (XmlNode node in fileNodes) { contain.Add(node.InnerText); } ModInformation information = new ModInformation(name, time, size, contain); return(information); } catch (Exception e) { if (shouldHave) { ExceptionHandler.ShowError(e, "获取 " + name + " 信息出错"); } return(null); } }
private void ListOperationsForm_Shown(object sender, EventArgs e) { grid.RowCount = m_Edits.Length; for (int i = 0; i < m_Edits.Length; i++) { Operation op = m_Edits[i]; DataGridViewRow row = grid.Rows[i]; row.Tag = op; row.Cells["opIdColumn"].Value = op.InternalId; row.Cells["operationColumn"].Value = op.Name; row.Cells["createdColumn"].Value = op.Session.StartTime.ToShortDateString(); row.Cells["editorColumn"].Value = op.Session.User; // If the line was created by a connection path, display the precision. if (op is PathOperation) { PathOperation path = (PathOperation)op; row.Cells["precisionColumn"].Value = path.GetPrecision(); } } grid.CurrentCell = null; }
private void PickPredecessorForm_Shown(object sender, EventArgs e) { grid.RowCount = m_Lines.Length; for (int i = 0; i < m_Lines.Length; i++) { LineFeature line = m_Lines[i]; Operation op = line.Creator; DataGridViewRow row = grid.Rows[i]; row.Tag = line; row.Cells["imageColumn"].Value = GetImage(op, line); row.Cells["opIdColumn"].Value = op.InternalId; row.Cells["operationColumn"].Value = op.Name; row.Cells["createdColumn"].Value = op.Session.StartTime.ToShortDateString(); row.Cells["editorColumn"].Value = op.Session.User; // If the line was created by a connection path, display the precision. if (op is PathOperation) { PathOperation path = (PathOperation)op; row.Cells["precisionColumn"].Value = path.GetPrecision(); } } grid.CurrentCell = null; }
public override IBuildIntention <IPathOperation> GetBuildIntention(IConversionContext context) { var(toBuild, maker) = PathOperation.Create(); return(new BuildIntention <IPathOperation>(toBuild, () => { maker.Build(Left.GetOrThrow().ConvertElementOrThrow(context), Right.GetOrThrow().ConvertElementOrThrow(context)); })); }
/// <summary> /// Create a new <c>PathInfo</c> object that corresponds to a previously /// saved connection path. For consistency with the other constructor, this /// does not attempt to adjust the path (the Rotation and ScaleFactory properties /// will retain zero values unless a call is made to Adjust). /// </summary> /// <param name="pop">The saved connection path</param> internal PathInfo(PathOperation pop) { m_From = pop.StartPoint; m_To = pop.EndPoint; m_Legs = pop.GetLegs(); m_IsAdjusted = false; m_Rotation = 0.0; m_ScaleFactor = 0.0; m_Precision = 0.0; }
/// <summary> /// 删除Mod /// </summary> /// <param name="name">欲删除Mod的文件名</param> /// <returns>成功则返回真</returns> public bool DeleteMod(string name) { List <ReplacedInformation> informations = GetReplacedFiles(); List <string> installedFilesPaths = new List <string>(); foreach (ReplacedInformation i in informations) { if (i.name == name) { installedFilesPaths.Add(i.path); } } if (installedFilesPaths.Count > 0) { string warningText = "该Mod的部分文件已经被安装" + Environment.NewLine; foreach (string path in installedFilesPaths) { warningText += path + Environment.NewLine; } warningText += "是否仍要删除该Mod与已安装文件?"; DialogResult result = MessageBox.Show(warningText, "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.No) { return(true); } } try { File.Delete(PathOperation.GetModsStorePath() + "\\" + name + ".mod"); //删除Index中的节点 XmlDocument xml = new XmlDocument(); xml.Load(PathOperation.GetModsIndexPath()); XmlNode node = xml.SelectSingleNode("mods/mod_" + name); if (node != null) { xml.DocumentElement.RemoveChild(node); } xml.Save(PathOperation.GetModsIndexPath()); //删除已替换文件 UnInstallFiles(installedFilesPaths, false); return(true); } catch (Exception e) { ExceptionHandler.ShowError(e, "无法删除Mod"); return(false); } }
/// <summary> /// 导入mod,移动源文件到config/mods目录下,删除源文件后创建配置文件 /// </summary> /// <param name="sourcePath"></param> /// <returns></returns> public bool ImportMod(string sourcePath) { if (Path.GetExtension(sourcePath) != ".zip") { MessageBox.Show("暂不支持的文件类型", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } //获取用户mod命名 string newName = String.Empty; Form_InputModName form_InputModName = new Form_InputModName(); form_InputModName.textBox.Text = Path.GetFileNameWithoutExtension(sourcePath); form_InputModName.textBox.Focus(); form_InputModName.textBox.SelectAll(); DialogResult result = form_InputModName.ShowDialog(); if (result != DialogResult.OK) { return(false); } newName = form_InputModName.textBox.Text; form_InputModName.Close(); //检测重名 if (GetModInformation(newName, false) != null) { DialogResult dialogResult = MessageBox.Show("已经存在同名文件,是否进行覆盖?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (dialogResult == DialogResult.Yes) { DeleteMod(newName); } else { return(false); } } try { File.Copy(sourcePath, PathOperation.GetModsStorePath() + "\\" + newName + ".mod"); InitNewMod(PathOperation.GetModsStorePath() + "\\" + newName + ".mod"); return(true); } catch (Exception e) { ExceptionHandler.ShowError(e, "移动文件出现错误"); return(false); } }
/// <summary> /// Fills the data entry field with the stuff that was entered for /// a specific connection path. /// </summary> /// <param name="op">The operation to show.</param> void ShowInput(PathOperation op) { // Return if the operation has not been specified. if (op == null) { return; } // Get the data entry string. string str = op.EntryString; // Display the data entry string (this takes care of word wrap). pathTextBox.Text = str; }
/// <summary> /// Initializes a new instance of the <see cref="LegFace"/> class /// using the data read from persistent storage. /// </summary> /// <param name="editDeserializer">The mechanism for reading back content.</param> internal LegFace(EditDeserializer editDeserializer) { // Only connection paths should generate LegFace instances PathOperation op = (editDeserializer.CurrentEdit as PathOperation); if (op == null) { throw new ApplicationException("Unexpected creating edit for a leg face"); } this.Sequence = editDeserializer.ReadInternalId(DataField.Id); if (editDeserializer.IsNextField(DataField.PrimaryFaceId)) { InternalIdValue primaryFaceId = editDeserializer.ReadInternalId(DataField.PrimaryFaceId); LegFace face = op.FindFace(primaryFaceId); if (face == null) { throw new ApplicationException("Cannot locate primary face " + primaryFaceId); } Leg = face.Leg; Leg.AlternateFace = this; } else { // This should never happen. Primary faces are not serialized using the LegFace // class (we only use LegFace as part of a PathOperation to simplify import of // extra legs from old CEdit files). throw new ApplicationException(); } // Convert the data entry string into observed spans string entryString = editDeserializer.ReadString(DataField.EntryString); DistanceUnit defaultEntryUnit = EditingController.Current.EntryUnit; Distance[] dists = LineSubdivisionFace.GetDistances(entryString, defaultEntryUnit, false); m_Spans = new SpanInfo[dists.Length]; for (int i = 0; i < m_Spans.Length; i++) { m_Spans[i] = new SpanInfo() { ObservedDistance = dists[i] }; } }
public bool UnInstallFiles(List <string> paths, bool needWarn) { if (needWarn) { string warningText; warningText = "确认要卸载以下文件?" + Environment.NewLine; foreach (string path in paths) { warningText += path + Environment.NewLine; } DialogResult result = MessageBox.Show(warningText, "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.No) { return(true); } } try { XmlDocument xml = new XmlDocument(); xml.Load(PathOperation.GetReplacedFilePath()); foreach (string path in paths) { foreach (XmlNode node in xml.SelectNodes("replaced/file")) { Console.WriteLine(path); if (path == node.InnerText) { xml.DocumentElement.RemoveChild(node); break; } } File.Delete(PathOperation.GetGamePath(false) + "\\mods\\" + path); } xml.Save(PathOperation.GetReplacedFilePath()); return(true); } catch (Exception e) { ExceptionHandler.ShowError(e, "卸载所选文件出错"); return(false); } }
private void PathForm_Shown(object sender, EventArgs e) { // Display at top left corner of the screen. this.Location = new Point(0, 0); // If we are recalling an old operation, fill in the // data entry string. PathOperation op = null; if (m_Command != null) { op = (m_Command.Recall as PathOperation); } ShowInput(op); // Display the current default units. m_Units = EditingController.Current.EntryUnit; if (m_Units == null) { defaultUnitsLabel.Text = String.Empty; } else { defaultUnitsLabel.Text = String.Format("{0}... ", m_Units.Abbreviation); } // Disable the "Preview" & "OK" buttons. They are only valid // after the from- and to-points have been entered, and after // something has been entered for the path. this.NoPreview(); // If we already have a from and a to point, fill them // in and start in the data entry field. if (m_From != null && m_To != null) { m_Focus = fromTextBox; OnSelectPoint(m_From); m_Focus = toTextBox; OnSelectPoint(m_To); } //autoPreviewCheckBox.Checked = Settings.Default.AutoPreviewPath; }
/// <summary> /// 获取已经安装的文件路径及Mod名称 /// </summary> /// <returns></returns> public List <ReplacedInformation> GetReplacedFiles() { List <ReplacedInformation> replacedFiles = new List <ReplacedInformation>(); XmlDocument xml = new XmlDocument(); xml.Load(PathOperation.GetReplacedFilePath()); XmlNodeList nodeList = xml.SelectNodes("replaced/file"); foreach (XmlNode node in nodeList) { string path = node.InnerText; string name = node.Attributes["mod"].Value; ReplacedInformation information = new ReplacedInformation(path, name); replacedFiles.Add(information); } return(replacedFiles); }
private List <string> InitNewModFiles(string sourcePath) { List <string> list = new List <string>(); try { string tempPath = Path.GetTempPath() + "smm"; if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } ZipFile.ExtractToDirectory(sourcePath, tempPath); Console.WriteLine("已经 " + sourcePath + "解压至" + tempPath); string nTempPath = Path.GetTempPath() + @"smm_nFiles"; Directory.CreateDirectory(nTempPath); foreach (string filePath in Directory.GetFiles(tempPath, "*", SearchOption.AllDirectories)) { if (PathOperation.IsModFilePath(filePath)) { string nPath = PathOperation.NormolizeModFilePath(filePath); Console.WriteLine("标准路径为:" + nPath); list.Add(nPath); Directory.CreateDirectory(Path.GetDirectoryName(nTempPath + "\\" + nPath)); File.Copy(filePath, nTempPath + "\\" + nPath, true); } } File.Delete(sourcePath); if (list.Count > 0) { ZipFile.CreateFromDirectory(nTempPath, sourcePath, CompressionLevel.Fastest, false); } Directory.Delete(tempPath, true); Directory.Delete(nTempPath, true); return(list); } catch (Exception e) { ExceptionHandler.ShowError(e, "无法初始化Mod信息"); return(list); } }
private void InitNewMod(string sourcePath) { string name = Path.GetFileNameWithoutExtension(sourcePath); XmlDocument xml = new XmlDocument(); xml.Load(PathOperation.GetModsIndexPath()); XmlElement basic = xml.CreateElement("mod_" + name); XmlElement size = xml.CreateElement("size"); XmlElement time = xml.CreateElement("time"); //文件大小 FileInfo fileInfo = new FileInfo(sourcePath); size.InnerText = ((float)fileInfo.Length / 1024 / 1024).ToString("0.##"); basic.AppendChild(size); //文件时间 time.InnerText = fileInfo.CreationTime.ToString(); basic.AppendChild(time); //文件列表 XmlElement fileBasic = xml.CreateElement("files"); List <string> fileList = InitNewModFiles(sourcePath); if (fileList.Count == 0) { MessageBox.Show("这不是只狼Mod文件!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); DeleteMod(name); return; } foreach (string path in fileList) { XmlElement file = xml.CreateElement("file"); file.InnerText = path; fileBasic.AppendChild(file); } basic.AppendChild(fileBasic); xml.DocumentElement.AppendChild(basic); xml.Save(PathOperation.GetModsIndexPath()); }
/// <summary> /// 获取全部Mod信息 /// </summary> /// <returns>返回ModInformationList</returns> public List <ModInformation> GetAllModsInformation() { List <ModInformation> list = new List <ModInformation>(); try { foreach (string path in Directory.GetFiles(PathOperation.GetModsStorePath(), "*.mod", SearchOption.TopDirectoryOnly)) { ModInformation information = GetModInformation(Path.GetFileNameWithoutExtension(path), true); if (information != null) { list.Add(information); } } return(list); } catch (Exception e) { ExceptionHandler.ShowError(e, "检索全部Mod信息出错"); return(list); } }
private void PopulatePackageItemInfo(PackageItem item) { if (item == null) { __infoPicture.Image = null; __infoLbl.Text = null; return; } if (item.DescriptionImage == null) { __infoPicture.Visible = false; __infoLbl.Top = __infoPicture.Top; } else { __infoPicture.Image = item.DescriptionImage; __infoPicture.Visible = true; __infoLbl.Top = __infoPicture.Bottom + 3; } if (String.IsNullOrEmpty(item.Description)) { PathOperation po = item as PathOperation; if (po != null) { __infoLbl.Text = po.Path; } else { __infoLbl.Text = String.Format(Cult.CurrentCulture, InstallerResources.GetString("C_E_noInfo"), item.Name); } } else { __infoLbl.Text = item.Description; } }
/// <summary> /// Initializes a new instance of the <see cref="UpdatePathForm"/> class. /// </summary> /// <param name="update">The update command that's driving things (not null).</param> /// <exception cref="ArgumentNullException">If the supplied update command is null.</exception> internal UpdatePathForm(UpdateUI update) { InitializeComponent(); Owner = EditingController.Current.MainForm; if (update == null) { throw new ArgumentNullException(); } m_UpdCmd = update; m_CurFaceIndex = -1; m_pop = null; // Get the object that was selected for update. m_pop = (m_UpdCmd.GetOp() as PathOperation); if (m_pop == null) { throw new ArgumentException("Cannot obtain original connection path for update"); } // Get a working copy of the connection path legs // TODO - This will not be suitable in a situation where staggered legs have been created Leg[] legs = PathParser.CreateLegs(m_pop.EntryString, m_pop.EntryUnit); m_Faces = new List <LegFace>(); foreach (Leg leg in legs) { m_Faces.Add(leg.PrimaryFace); if (leg.AlternateFace != null) { m_Faces.Add(leg.AlternateFace); } } m_Edits = new PathEditor(legs); }
/// <summary> /// Rollforward this leg. /// </summary> /// <param name="insert">The point of the end of any new insert that /// immediately precedes this leg. This will be updated if this leg also /// ends with a new insert (if not, it will be returned as a null value).</param> /// <param name="op">The connection path that this leg belongs to.</param> /// <param name="terminal">The position for the start of the leg. Updated to be /// the position for the end of the leg.</param> /// <param name="bearing">The bearing at the end of the previous leg. /// Updated for this leg.</param> /// <param name="sfac">Scale factor to apply to distances.</param> /// <returns></returns> internal override bool Rollforward(ref PointFeature insert, PathOperation op, ref IPosition terminal, ref double bearing, double sfac) { throw new NotImplementedException(); /* * // SS:20080314 - This looks like Save... * * // Create an undefined circular span * CircularSpan span = new CircularSpan(this, terminal, bearing, sfac); * * // Create list for holding any newly created points * List<PointFeature> createdPoints = new List<PointFeature>(); * * // If this leg already has an associated circle, move it. Otherwise * // add a circle to the map that corresponds to this leg. * if (m_Circle == null) * m_Circle = AddCircle(op, createdPoints, span); * else * { * // Get the centre point associated with the current op. If there * // is one (i.e. it's not a point that existed before the op), just * // move it. Otherwise add a new circle (along with a new centre * // point). * * // Inactive centre points are ok (if you don't search for * // them, a new circle will be added). * * // 19-OCT-99: During rollforward, the op returned by SaveOp is * // the op where rollforward started (not necessarily the op * // that this leg belongs to). This probably needs to be changed * // for other reasons, but for now, use the op that was supplied * // (it was not previously supplied). If you don't do this, the * // GetpCentre call will not find the centre point, even if it * // was created by this leg, so it would always go to add a new * // circle. * * //const CeOperation* const pop = CeMap::GetpMap()->SaveOp(); * //CePoint* pCentre = m_pCircle->GetpCentre(pop,FALSE); * * PointFeature center = m_Circle.CenterPoint; * * if (Object.ReferenceEquals(center.Creator, op)) * { * // Get the span to modify the radius of the circle. * SetCircle(span, m_Circle); * * // Move the center point. * center.MovePoint(uc, span.Center); * } * else * { * // The existing center point makes reference to the * // circle, so clean that up. * center.CutReference(m_Circle); * * // 19-OCT-99: The AddCircle call just returns * // the circle that this leg already knows about, * // so clear it first. * m_Circle = null; * * // Add a new circle. * m_Circle = AddCircle(op, createdPoints, span); * } * } * * // Create (or update) features for each span. Note that for * // cul-de-sacs, there may be no observed spans. * int nspan = Math.Max(1, this.Count); * * for (int i = 0; i < nspan; i++) * { * SaveSpan(ref insert, op, createdPoints, span, i, uc); * } * * // Update BC info to refer to the EC. * terminal = span.EC; * bearing = span.ExitBearing; * return true; */ }
/// <summary> /// Defines the geometry for this leg. /// </summary> /// <param name="ctx">The context in which the geometry is being calculated</param> /// <param name="terminal">The position for the start of the leg. Updated to be /// the position for the end of the leg.</param> /// <param name="bearing">The bearing at the end of the previous leg. Updated for this leg.</param> /// <param name="sfac">Scale factor to apply to distances.</param> //abstract internal void CreateGeometry(EditingContext ctx, ref IPosition terminal, ref double bearing, double sfac); abstract internal bool Rollforward(ref PointFeature insert, PathOperation op, ref IPosition terminal, ref double bearing, double sfac);
public void Execute(PackageExecutionSettings settings) { /////////////////////////////////// // Prepare EnsureState(); if (IsBusy) { throw new InvalidOperationException("Cannot execute another package whilst executing a package."); } IsBusy = true; if (settings.LiteMode) { FactoryOptions.Populate(); FactoryOptions.Instance[Anolis.Core.Data.DirectoryResourceDataFactory.IconSizeLimit] = 128; } /////////////////////////////////// // Create Backup Details Group backupGroup = null; if (settings.BackupDirectory != null) { if (settings.BackupDirectory.Exists) { settings.BackupDirectory = new DirectoryInfo(PackageUtility.GetUnusedDirectoryName(settings.BackupDirectory.FullName)); } settings.BackupDirectory.Create(); settings.BackupDirectory.Refresh(); Package backupPackage = new Package(settings.BackupDirectory); backupPackage.Version = this.Version; backupPackage.Name = this.Name + " Uninstallation Package"; backupPackage.Attribution = "Anolis Installer"; backupPackage.FeedbackUri = this.FeedbackUri; backupGroup = backupPackage.RootGroup; } ExecutionInfo = new PackageExecutionSettingsInfo(this, settings.ExecutionMode, settings.CreateSystemRestorePoint, settings.LiteMode, backupGroup, settings.I386Directory); /////////////////////////////////// // Flatten Log.Add(LogSeverity.Info, "Beginning package execution: " + this.Name + ", with mode " + ExecutionInfo.ExecutionMode.ToString()); OnProgressEvent(new PackageProgressEventArgs(0, "Flattening Package Tree")); List <Operation> operations = new List <Operation>(); RootGroup.Flatten(operations); List <Operation> obsoleteOperations = new List <Operation>(); Dictionary <String, Operation> uniques = new Dictionary <String, Operation>(); foreach (Operation op in operations) { if (!op.IsEnabled) { obsoleteOperations.Add(op); continue; } Operation originalOperation; if (uniques.TryGetValue(op.Key, out originalOperation)) { if (originalOperation.Merge(op)) { obsoleteOperations.Add(op); } } else { uniques.Add(op.Key, op); } } operations.RemoveAll(op => obsoleteOperations.Contains(op)); /////////////////////////////////// // Prepare if (ExecutionInfo.ExecutionMode == PackageExecutionMode.Regular) { PackageUtility.AllowProtectedRenames(); } Int64 restorePointSequenceNumber = -2; /////////////////////////////////// // System Restore, Part 1 if (ExecutionInfo.ExecutionMode == PackageExecutionMode.Regular && ExecutionInfo.CreateSystemRestorePoint) { if (SystemRestore.IsSystemRestoreAvailable()) { OnProgressEvent(new PackageProgressEventArgs(-1, "Creating System Restore Point")); String pointName = "Installed Anolis Package \"" + this.Name + '"'; restorePointSequenceNumber = SystemRestore.CreateRestorePoint(pointName, SystemRestoreType.ApplicationInstall); if (restorePointSequenceNumber < 0) { Log.Add(LogSeverity.Error, "Failed to create System Restore point"); } } else { Log.Add(LogSeverity.Error, "System Restore not supported"); } } /////////////////////////////////// // Install (Backup and Execute; backups are the responisiblity of each Operation) try { float i = 0, cnt = operations.Count; foreach (Operation op in operations) { OnProgressEvent(new PackageProgressEventArgs((int)(100 * i++ / cnt), op.ToString())); if (!op.SupportsCDImage && ExecutionInfo.ExecutionMode == PackageExecutionMode.CDImage) { continue; } try { if (op.CustomEvaluation) { op.Execute(); } else { EvaluationResult result = op.Evaluate(); switch (result) { case EvaluationResult.False: Log.Add(LogSeverity.Info, "Evaluation False - " + op.Key); break; case EvaluationResult.FalseParent: Log.Add(LogSeverity.Info, "Evaluation ParentFalse - " + op.Key); break; case EvaluationResult.Error: Log.Add(LogSeverity.Error, "Evaluation Error - " + op.Key); break; case EvaluationResult.True: op.Execute(); break; } } } catch (Exception ex) { Log.Add(new LogItem(LogSeverity.Error, ex, op.Name + " failed: \"" + ex.Message + "\"")); continue; } #if !DEBUG // don't add "Info - Done {op}" in debug mode because it's too verbose and clutters up the logfile PathOperation pathOp = op as PathOperation; if (pathOp != null) { Log.Add(LogSeverity.Info, "Done " + op.Name + ": " + pathOp.Path); } else { Log.Add(LogSeverity.Info, "Done " + op.Name); } #endif } //foreach OnProgressEvent(new PackageProgressEventArgs(100, "Complete")); } finally { /////////////////////////////////// // System Restore, Part 2 if (restorePointSequenceNumber >= 0) { OnProgressEvent(new PackageProgressEventArgs(-1, "Finishing System Restore Point")); SystemRestore.EndRestorePoint(restorePointSequenceNumber); } /////////////////////////////////// // Backup, Part 2 if (ExecutionInfo.BackupGroup != null) { String backupFileName = Path.Combine(ExecutionInfo.BackupDirectory.FullName, "Package.xml"); ExecutionInfo.BackupPackage.Write(backupFileName); } /////////////////////////////////// // Dump the log to disk Log.Save(Path.Combine(this.RootDirectory.FullName, "Anolis.Installer.log")); IsBusy = false; } //try/finally }
public MirrorPointImplementation() { var keyX = new NameKey("x"); var localX = MemberDefinition.CreateAndBuild(keyX, new AnyType(), false); var keyY = new NameKey("y"); var localY = MemberDefinition.CreateAndBuild(keyY, new AnyType(), false); var contextKey = new NameKey("context"); var context = MemberDefinition.CreateAndBuild( contextKey, InterfaceType.CreateAndBuild( Scope.CreateAndBuild( new List <Scope.IsStatic>() { new Scope.IsStatic(localX, false), new Scope.IsStatic(localY, false), }).Members), false);; var inputKey = new NameKey("input"); var input = MemberDefinition.CreateAndBuild(inputKey, new EmptyType(), false); var tempKey = new NameKey("temp"); var temp = MemberDefinition.CreateAndBuild(tempKey, new AnyType(), false); var implementationScope = Scope.CreateAndBuild( new List <Scope.IsStatic> { new Scope.IsStatic(input, false), new Scope.IsStatic(temp, false) }); Module = ModuleDefinition.CreateAndBuild( Scope.CreateAndBuild( new List <Scope.IsStatic>() { new Scope.IsStatic(MemberDefinition.CreateAndBuild(new NameKey("mirror"), new AnyType(), false), false) }), new[] { AssignOperation.CreateAndBuild( ImplementationDefinition.CreateAndBuild( new EmptyType(), context, input, implementationScope, new ICodeElement[] { AssignOperation.CreateAndBuild( PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localX)), MemberReference.CreateAndBuild(temp) ), AssignOperation.CreateAndBuild( PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localY)), PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localX)) ), AssignOperation.CreateAndBuild( MemberReference.CreateAndBuild(temp), PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localY)) ) }, new ICodeElement[0]), MemberReference.CreateAndBuild(MemberDefinition.CreateAndBuild(new NameKey("mirror"), new AnyType(), false))) }, new NameKey("mirror-module")); }
private void Add(PathOperation operation) { Operations.Add(operation); }
/* * /// <summary> * /// Defines the geometry for this leg. * /// </summary> * /// <param name="ctx">The context in which the geometry is being calculated</param> * /// <param name="terminal">The position for the start of the leg. Updated to be * /// the position for the end of the leg.</param> * /// <param name="bearing">The bearing at the end of the previous leg. Updated for this leg.</param> * /// <param name="sfac">Scale factor to apply to distances.</param> * internal override void CreateGeometry(EditingContext ctx, ref IPosition terminal, ref double bearing, double sfac) * { * // Add on any initial angle (it may be a deflection). * bearing = AddStartAngle(bearing); * * // Create a straight span * StraightSpan span = new StraightSpan(terminal, bearing, sfac); * * int nspan = this.Count; * for (int i = 0; i < nspan; i++) * { * // Get info for the current span (this defines the * // adjusted start and end positions, among other things). * span.Get(this, i); * * // Create the geometry for the point at the end of the span * SpanInfo data = GetSpanData(i); * Feature feat = data.CreatedFeature; * PointFeature endPoint = null; * * if (feat is PointFeature) * endPoint = (PointFeature)feat; * else if (feat is LineFeature) * endPoint = (feat as LineFeature).EndPoint; * * if (endPoint != null && endPoint.PointGeometry == null) * endPoint.ApplyPointGeometry(ctx, PointGeometry.Create(span.End)); * } * * // Return the end position of the last span. * terminal = span.End; * } */ /// <summary> /// Rollforward this leg. /// </summary> /// <param name="insert">The point of the end of any new insert that /// immediately precedes this leg. This will be updated if this leg also /// ends with a new insert (if not, it will be returned as a null value).</param> /// <param name="op">The connection path that this leg belongs to.</param> /// <param name="terminal">The position for the start of the leg. Updated to be /// the position for the end of the leg.</param> /// <param name="bearing">The bearing at the end of the previous leg. /// Updated for this leg.</param> /// <param name="sfac">Scale factor to apply to distances.</param> /// <returns></returns> internal override bool Rollforward(ref PointFeature insert, PathOperation op, ref IPosition terminal, ref double bearing, double sfac) { throw new NotImplementedException(); /* * // Add on any initial angle (it may be a deflection). * if (Math.Abs(m_StartAngle) > MathConstants.TINY) * { * if (m_IsDeflection) * bearing += m_StartAngle; * else * bearing += (m_StartAngle-Math.PI); * } * * // Create a straight span * StraightSpan span = new StraightSpan(this, terminal, bearing, sfac); * * // The very end of a connection path should never be moved. * PointFeature veryEnd = op.EndPoint; * * // Create list for holding any newly created points * List<PointFeature> createdPoints = new List<PointFeature>(); * * int nspan = this.Count; * for (int i=0; i<nspan; i++) * { * // Get info for the current span (this defines the * // adjusted start and end positions, among other things). * span.Get(i); * * // If we've got a newly inserted span * if (IsNewSpan(i)) * { * bool isLast = (i==(nspan-1) && op.IsLastLeg(this)); * LineFeature newLine = SaveInsert(span, i, op, isLast); * AddNewSpan(i, newLine); * insert = newLine.EndPoint; * } * else * { * // See if the span previously had a saved feature. * Feature old = GetFeature(i); * if (old!=null) * SaveSpan(span, op, createdPoints, insert, old, veryEnd, uc); * else * { * Feature feat = SaveSpan(span, op, createdPoints, insert, null, veryEnd, uc); * SetFeature(i, feat); * } * * // That wasn't an insert. * insert = null; * } * } * * // Return the end position of the last span. * terminal = span.End; * return true; */ }
private void Write(PathOperation op, bool relative, params Vector2[] points) { byte o = (byte)op; o &= 0x7f; if (relative) o |= 0x80; _writer.Write(o); foreach (var point in points) { _writer.Write(point.X); _writer.Write(point.Y); } }
public MirrorPointImplementation() { var keyX = new NameKey("x"); var localX = MemberDefinition.CreateAndBuild(keyX, new AnyType(), Access.ReadWrite); var keyY = new NameKey("y"); var localY = MemberDefinition.CreateAndBuild(keyY, new AnyType(), Access.ReadWrite); var contextKey = new NameKey("context"); var context = MemberDefinition.CreateAndBuild( contextKey, InterfaceType.CreateAndBuild( Scope.CreateAndBuild( new List <IsStatic>() { new IsStatic(localX, false), new IsStatic(localY, false), }).Members.Values.Select(x => x.Value).ToList()), Access.ReadWrite);; var inputKey = new NameKey("input"); var input = MemberDefinition.CreateAndBuild(inputKey, new EmptyType(), Access.ReadWrite); var tempKey = new NameKey("temp"); var temp = MemberDefinition.CreateAndBuild(tempKey, new AnyType(), Access.ReadWrite); var implementationScope = Scope.CreateAndBuild( new List <IsStatic> { new IsStatic(input, false), new IsStatic(temp, false) }); var intermediateScope = Scope.CreateAndBuild( new List <IsStatic> { new IsStatic(context, false) }); RootScope = Model.Instantiated.RootScope.CreateAndBuild( Scope.CreateAndBuild( new List <IsStatic>() { new IsStatic(MemberDefinition.CreateAndBuild(new NameKey("mirror"), new AnyType(), Access.ReadWrite), false) }), new[] { AssignOperation.CreateAndBuild( ImplementationDefinition.CreateAndBuild( new EmptyType(), context, input, implementationScope, new ICodeElement[] { AssignOperation.CreateAndBuild( PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localX)), MemberReference.CreateAndBuild(temp) ), AssignOperation.CreateAndBuild( PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localY)), PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localX)) ), AssignOperation.CreateAndBuild( MemberReference.CreateAndBuild(temp), PathOperation.CreateAndBuild(MemberReference.CreateAndBuild(context), MemberReference.CreateAndBuild(localY)) ) }, Array.Empty <ICodeElement>(), intermediateScope), MemberReference.CreateAndBuild(MemberDefinition.CreateAndBuild(new NameKey("mirror"), new AnyType(), Access.ReadWrite))) }, EntryPointDefinition.CreateAndBuild(new EmptyType(), MemberDefinition.CreateAndBuild(new NameKey("input"), new NumberType(), Access.ReadWrite), Scope.CreateAndBuild(Array.Empty <IsStatic>()), Array.Empty <ICodeElement>(), Array.Empty <ICodeElement>())); }
/// <summary> /// 安装所给文件 /// </summary> /// <param name="name">欲安装文件的Mod名称</param> /// <param name="paths">欲安装的文件列表</param> /// <returns>若成功安装,返回真</returns> public bool InstallFiles(string name, List <string> paths) { XmlDocument xml = new XmlDocument(); xml.Load(PathOperation.GetReplacedFilePath()); if (paths.Count == 0) { return(true); } try { //检测冲突 List <ReplacedInformation> replacedFiles = GetReplacedFiles(); List <ReplacedInformation> conflictFiles = new List <ReplacedInformation>(); foreach (ReplacedInformation i in replacedFiles) { foreach (string path in paths) { if (path == i.path) { conflictFiles.Add(i); break; } } } //若有冲突,弹出警告 if (conflictFiles.Count > 0) { string warningText = "以下Mod文件有冲突:" + Environment.NewLine; foreach (ReplacedInformation i in conflictFiles) { warningText += i.name + " 中的 " + i.path + Environment.NewLine; } warningText += "是否要覆盖上述文件?"; DialogResult result = MessageBox.Show(warningText, "警告", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.No) { return(true); } //若选择继续覆盖,删除原有文件及XML信息 foreach (ReplacedInformation i in conflictFiles) { File.Delete(PathOperation.GetGamePath(false) + "\\mods\\" + i.path); foreach (XmlNode node in xml.SelectNodes("replaced/file")) { if (node.InnerText == i.path) { xml.DocumentElement.RemoveChild(node); break; } } } } //保存配置文件 foreach (string path in paths) { XmlElement ele = xml.CreateElement("file"); ele.InnerText = path; ele.SetAttribute("mod", name); xml.DocumentElement.AppendChild(ele); } xml.Save(PathOperation.GetReplacedFilePath()); //解压文件 string targetPath = PathOperation.GetGamePath(false) + @"\mods"; string sourcePath = PathOperation.GetModsStorePath() + "\\" + name + ".mod"; //解压至临时目录 string tempPath = Path.GetTempPath() + "smm"; if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } ZipFile.ExtractToDirectory(sourcePath, tempPath); Console.WriteLine("已经 " + sourcePath + "解压至" + tempPath); foreach (string path in paths) { if (!Directory.Exists(targetPath + "\\" + Path.GetDirectoryName(path))) { Directory.CreateDirectory(targetPath + "\\" + Path.GetDirectoryName(path)); } File.Copy(tempPath + "\\" + path, targetPath + "\\" + path); } Directory.Delete(tempPath, true); MessageBox.Show("所选文件已安装成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } catch (Exception e) { ExceptionHandler.ShowError(e, "安装文件出现错误"); return(false); } }