当前位置: 首页>>代码示例>>C#>>正文


C# ModuleInfo.Save方法代码示例

本文整理汇总了C#中ModuleInfo.Save方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleInfo.Save方法的具体用法?C# ModuleInfo.Save怎么用?C# ModuleInfo.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModuleInfo的用法示例。


在下文中一共展示了ModuleInfo.Save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoInstall


//.........这里部分代码省略.........

                // Now loop through all of the haks and make any module changes
                // required.
                foreach (HakInfo hakInfo in hakInfos)
                {
                    // Set all of the module properties.
                    Progress(progress, true, "Setting module properties for {0}", moduleFile);
                    PropertyHandlerDictionary handlers = objects["Module"];
                    foreach (DictionaryEntry entry in hakInfo.ModuleProperties)
                    {
                        if (progress.IsCancelled) throw new InstallCancelledException();

                        // Resolve the DictionaryEntry to native data.
                        string property = (string) entry.Key;
                        StringCollection values = (StringCollection) entry.Value;
                        if (0 == values.Count) continue;

                        // Look up the handler for the property, throwing an exception
                        // if we don't find one, then invoke it.
                        PropertyHandler handler = handlers[property];
                        if (null == handler)
                            throw new InvalidOperationException("Unknown module property " + property);
                        handler(module, moduleInfo, property, values);
                    }
                }

                // If we have a merge hak then add it now so it goes to the top of
                // the hak list.
                if (string.Empty != mergeHak)
                {
                    StringCollection mergeHakCollection = new StringCollection();
                    mergeHakCollection.Add(mergeHak);
                    Module_Hak(module, moduleInfo, "hak", mergeHakCollection);
                }

                // Build string arrays of the hif names and versions of all of the HakInfo
                // objects we added to the module, then update the module's installed
                // HakInfo property.  This is a custom property used by this tool to
                // keep track of what is installed on a module.
                string[] hifs = new string[hakInfos.Length];
                float[] versions = new float[hakInfos.Length];
                for (int i = 0; i < hakInfos.Length; i++)
                {
                    hifs[i] = hakInfos[i].Name;
                    versions[i] = hakInfos[i].Version;
                }
                moduleInfo.AddInstalledHakInfos(hifs, versions);

                // Save the changes to the module info file.
                moduleInfo.Save();

                // Backup the old module file before saving.
                string backupName = Path.Combine(NWNInfo.GetPathForFile(moduleFile),
                    Path.GetFileNameWithoutExtension(moduleFile) + ".BackupMod");
                File.Copy(NWNInfo.GetFullFilePath(moduleFile), backupName, true);

                // Recreate the module file with our changed files.
                Progress(progress, true, "Saving {0}", moduleFile);
                module.RecreateFile();

                // If we created merge files then display a message to the user
                // telling them what we did.
                if (string.Empty != mergeHak || string.Empty != mergeTlk)
                {
                    string files = "\r\n\r\n\t";
                    if (string.Empty != mergeHak) files += NWN.NWNInfo.GetPartialFilePath(mergeHak);
                    if (string.Empty != mergeTlk)
                    {
                        if (string.Empty != files) files += "\r\n\t";
                        files += NWN.NWNInfo.GetPartialFilePath(mergeTlk);
                    }

                    progress.DisplayMessage(string.Format(
                        "There were conflicts between the custom content you are trying to add and " +
                        "the files already used by the module '{0}'.  Merge files were created to resolve " +
                        "these conflicts, you should delete these files when you are finished " +
                        "with your module." + files, Path.GetFileNameWithoutExtension(module.FileName)));
                }
            }
            catch (Exception e)
            {
                // Delete any merge files we created, the install is failing.s
                if (string.Empty != mergeTlk) File.Delete(NWN.NWNInfo.GetFullFilePath(mergeTlk));
                if (string.Empty != mergeHak) File.Delete(NWN.NWNInfo.GetFullFilePath(mergeHak));

                // If the exception isn't an InstallCancelledException then throw it.
                // InstallCancelledExceptions are thrown to abort the install, we want to eat those.
                if (!(e is InstallCancelledException)) throw;
            }
            finally
            {
                // Always clean up temp dirs no matter what.
                foreach (string dir in tempDirs)
                    try
                    {
                        if (Directory.Exists(dir)) Directory.Delete(dir, true);
                    }
                    catch{}
            }
        }
开发者ID:BackupTheBerlios,项目名称:nwnprc,代码行数:101,代码来源:HakInstaller.cs


注:本文中的ModuleInfo.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。