private static void ProcessLevel(string path, LevelLocation location)
 {
     try
     {
         Main.SpecialCode = "Loading Level " + path != null ? path : "null";
         if (!path.EndsWith(".lev"))
         {
             return;
         }
         path = path.Replace('\\', '/');
         LevelData dat = location != LevelLocation.Content ? DuckFile.LoadLevel(path) : DuckFile.LoadLevel(DuckFile.ReadEntireStream(TitleContainer.OpenStream(path)));
         if (dat != null)
         {
             dat.SetPath(path);
             path = path.Substring(0, path.Length - 4);
             path.Substring(path.IndexOf("/levels/") + 8);
             if (dat.metaData.guid != null)
             {
                 DuckGame.Content.MapLevel(dat.metaData.guid, dat, location);
             }
         }
         ++MonoMain.loadyBits;
     }
     catch (Exception ex)
     {
         DuckGame.Content.LogLevelFailure(ex.ToString());
     }
 }
示例#2
0
        private static void PrepareToLoadCloudFile(string path)
        {
            if (!Options.Data.cloud || !Steam.IsInitialized())
            {
                return;
            }
            string localSavePath = DuckFile.GetLocalSavePath(path);

            if (localSavePath == null)
            {
                return;
            }
            byte[] buffer = Steam.FileRead("nq403216_" + localSavePath);
            if (buffer == null)
            {
                return;
            }
            if (File.Exists(path))
            {
                File.Delete(path);
            }
            FileStream fileStream = File.Create(path);

            fileStream.Write(buffer, 0, buffer.Length);
            fileStream.Close();
        }
示例#3
0
 public bool Filter(string lev, LevelLocation location = LevelLocation.Any)
 {
     try
     {
         LevelType levelType = LevelType.Invalid;
         if (LSFilterLevelType._types.TryGetValue(lev, out levelType))
         {
             return(levelType == this._type);
         }
         LevelData levelData = (LevelData)null;
         if (!LSItem.bullshitLevelCache.TryGetValue(lev, out levelData))
         {
             levelData = DuckFile.LoadLevel(lev);
             LSItem.bullshitLevelCache[lev] = levelData;
         }
         if (levelData == null)
         {
             LSFilterLevelType._types[lev] = LevelType.Invalid;
             return(false);
         }
         if (this._needsDeathmatchTag && location == LevelLocation.Workshop && (levelData.metaData.workshopID != 0UL && !levelData.metaData.deathmatchReady))
         {
             LSFilterLevelType._types[lev] = LevelType.Strange;
             return(false);
         }
         LevelType type = levelData.metaData.type;
         LSFilterLevelType._types[lev] = type;
         return(type == this._type);
     }
     catch
     {
         LSFilterLevelType._types[lev] = LevelType.Invalid;
         return(false);
     }
 }
示例#4
0
 public static string[] GetFiles(string path, string filter, SearchOption option = SearchOption.TopDirectoryOnly)
 {
     DuckFile._getFilesOption = option;
     string[] files = DuckFile.GetFiles(path, filter);
     DuckFile._getFilesOption = SearchOption.TopDirectoryOnly;
     return(files);
 }
示例#5
0
        public static void DownloadAllCloudData()
        {
            bool cloudOnly = MonoMain.cloudOnly;
            bool cloud     = Options.Data.cloud;

            MonoMain.cloudOnly = true;
            Options.Data.cloud = true;
            foreach (string file in DuckFile.GetFiles(DuckFile.profileDirectory, "*.*", SearchOption.AllDirectories))
            {
                DuckFile.CreatePath(file);
                DuckFile.PrepareToLoadCloudFile(file);
            }
            foreach (string file in DuckFile.GetFiles(DuckFile.levelDirectory, "*.*", SearchOption.AllDirectories))
            {
                DuckFile.CreatePath(file);
                DuckFile.PrepareToLoadCloudFile(file);
            }
            foreach (string file in DuckFile.GetFiles(DuckFile.optionsDirectory, "*.*", SearchOption.AllDirectories))
            {
                DuckFile.CreatePath(file);
                DuckFile.PrepareToLoadCloudFile(file);
            }
            MonoMain.cloudOnly = cloudOnly;
            Options.Data.cloud = cloud;
        }
示例#6
0
        public static List <string> GetFilesNoCloud(string path, string filter = "*.*", SearchOption so = SearchOption.TopDirectoryOnly)
        {
            List <string> stringList = new List <string>();

            try
            {
                foreach (string file in Directory.GetFiles(path, filter, SearchOption.TopDirectoryOnly))
                {
                    stringList.Add(file);
                }
            }
            catch (Exception ex)
            {
            }
            if (so == SearchOption.AllDirectories)
            {
                try
                {
                    foreach (string directory in Directory.GetDirectories(path, "*.*", SearchOption.TopDirectoryOnly))
                    {
                        List <string> filesNoCloud = DuckFile.GetFilesNoCloud(directory, filter, so);
                        stringList.AddRange((IEnumerable <string>)filesNoCloud);
                    }
                }
                catch (Exception ex)
                {
                }
            }
            return(stringList);
        }
示例#7
0
        public static string[] GetDirectories(string path)
        {
            path = path.Replace('\\', '/');
            List <string> stringList = new List <string>();

            if (Options.Data.cloud && !MonoMain.disableCloud && Steam.IsInitialized())
            {
                string localSavePath = DuckFile.GetLocalSavePath(path);
                if (localSavePath != null)
                {
                    int count = Steam.FileGetCount();
                    for (int file = 0; file < count; ++file)
                    {
                        string name = Steam.FileGetName(file);
                        int    num  = name.IndexOf(localSavePath);
                        if (num != -1 && name.StartsWith("nq403216_"))
                        {
                            if (localSavePath == "")
                            {
                                num += 12;
                            }
                            string str1   = name.Substring(num + localSavePath.Length, name.Length - (num + localSavePath.Length));
                            int    length = str1.IndexOf('/');
                            switch (length)
                            {
                            case -1:
                            case 0:
                                continue;

                            default:
                                string str2 = path + str1.Substring(0, length);
                                if (!stringList.Contains(str2))
                                {
                                    stringList.Add(str2);
                                    continue;
                                }
                                continue;
                            }
                        }
                    }
                }
            }
            path = path.Trim('/');
            if (!MonoMain.cloudOnly && Directory.Exists(path))
            {
                foreach (string path1 in DuckFile.GetDirectoriesNoCloud(path))
                {
                    if (!Path.GetFileName(path1).Contains("._"))
                    {
                        string str = path1.Replace('\\', '/');
                        if (!stringList.Contains(str))
                        {
                            stringList.Add(str);
                        }
                    }
                }
            }
            return(stringList.ToArray());
        }
示例#8
0
 public static void CompleteSteamCloudInitializate()
 {
     if (!DuckFile.needsCloudInit)
     {
         return;
     }
     DuckFile.UploadAllCloudData();
 }
示例#9
0
 public static void DeleteAllSaveData()
 {
     foreach (string allPath in DuckFile._allPaths)
     {
         foreach (string file in DuckFile.GetFiles(DuckFile.saveDirectory + allPath))
         {
             DuckFile.Delete(file);
         }
     }
 }
示例#10
0
 public static void Initialize()
 {
     foreach (string level1 in Content.GetLevels("challenge", LevelLocation.Content))
     {
         LevelData level2 = Content.GetLevel(level1);
         string    guid   = level2.metaData.guid;
         foreach (BinaryClassChunk node in level2.objects.objects)
         {
             string property = node.GetProperty <string>("type");
             if (property != null)
             {
                 if (property.Contains("DuckGame.ChallengeMode,"))
                 {
                     try
                     {
                         if (Thing.LoadThing(node, false) is ChallengeMode challengeMode)
                         {
                             challengeMode.challenge.fileName = level1;
                             challengeMode.challenge.levelID  = guid;
                             challengeMode.challenge.preview  = level2.previewData.preview;
                             if (challengeMode.challenge.trophies[5].goodies == -1 && challengeMode.challenge.trophies[5].targets == -1)
                             {
                                 int timeRequirement = challengeMode.challenge.trophies[5].timeRequirement;
                             }
                             Challenges._challenges.Add(level2.metaData.guid, challengeMode.challenge);
                         }
                     }
                     catch (Exception ex)
                     {
                     }
                 }
             }
         }
     }
     foreach (string file in DuckFile.GetFiles(DuckFile.challengeDirectory))
     {
         XDocument xdocument = DuckFile.LoadXDocument(file);
         if (xdocument != null)
         {
             string   withoutExtension = Path.GetFileNameWithoutExtension(file);
             XElement xelement         = xdocument.Element((XName)"Data");
             if (xelement != null)
             {
                 foreach (XElement element1 in xelement.Elements((XName)"challengeSaveData"))
                 {
                     ChallengeSaveData element2 = new ChallengeSaveData();
                     element2.LegacyDeserialize(element1);
                     element2.challenge = withoutExtension;
                     Challenges._saveData.Add(withoutExtension, element2);
                 }
             }
         }
     }
 }
示例#11
0
 public static List <string> GetFilesInternal <T>(string path, List <string> files, string ext)
 {
     foreach (string file in DuckFile.GetFiles(path, ext))
     {
         files.Add(file);
     }
     foreach (string directory in DuckGame.Content.GetDirectories(path))
     {
         DuckGame.Content.GetFilesInternal <T>(directory, files, ext);
     }
     return(files);
 }
示例#12
0
 public static void InitializeCloud()
 {
     if (!Steam.IsInitialized())
     {
         return;
     }
     try
     {
         string localSavePath = DuckFile.GetLocalSavePath(DuckFile.optionsDirectory + "options.dat");
         if (localSavePath == null)
         {
             return;
         }
         if (!Steam.FileExists("nq403216_" + localSavePath))
         {
             return;
         }
         try
         {
             XDocument xdocument = XDocument.Load((Stream) new MemoryStream(Steam.FileRead("nq403216_" + localSavePath)));
             if (xdocument != null)
             {
                 Profile profile = new Profile("");
                 IEnumerable <XElement> source = xdocument.Elements((XName)"Data");
                 if (source != null)
                 {
                     foreach (XElement element in source.Elements <XElement>())
                     {
                         if (element.Name.LocalName == "Options")
                         {
                             OptionsData optionsData = new OptionsData();
                             optionsData.Deserialize(element);
                             if (optionsData.cloud)
                             {
                                 DuckFile.cloudOverload = true;
                             }
                             Options.Data.cloud = optionsData.cloud;
                             break;
                         }
                     }
                 }
             }
         }
         catch (Exception ex)
         {
         }
         DuckFile.needsCloudInit = false;
     }
     catch (Exception ex)
     {
     }
 }
示例#13
0
 protected override void OnStart()
 {
     Options.Initialize();
     Global.Initialize();
     Teams.Initialize();
     DuckRig.Initialize();
     Unlocks.Initialize();
     ConnectionStatusUI.Initialize();
     Unlocks.CalculateTreeValues();
     Profiles.Initialize();
     Dialogue.Initialize();
     DuckTitle.Initialize();
     News.Initialize();
     Script.Initialize();
     DuckNews.Initialize();
     VirtualBackground.InitializeBack();
     AmmoType.InitializeTypes();
     DestroyType.InitializeTypes();
     VirtualTransition.Initialize();
     Unlockables.Initialize();
     UIInviteMenu.Initialize();
     LevelGenerator.Initialize();
     DuckFile.CompleteSteamCloudInitializate();
     Main.ResetMatchStuff();
     foreach (Profile profile in Profiles.active)
     {
         profile.RecordPreviousStats();
     }
     Main.editor = new DuckGameEditor();
     foreach (string file in DuckFile.GetFiles(Directory.GetCurrentDirectory(), "*.hat"))
     {
         Team t = Team.Deserialize(file);
         if (t != null)
         {
             Teams.AddExtraTeam(t);
         }
     }
     Main.SetPurchaseDetails(9.99f, "USD");
     if (Main.connectID != 0UL)
     {
         NCSteam.inviteLobbyID = Main.connectID;
         Level.current         = (Level) new JoinServer(Main.connectID);
     }
     else
     {
         Level.current = !MonoMain.noIntro ? (Level) new BIOSScreen() : (!MonoMain.startInEditor ? (Level) new TitleScreen() : (Level)Main.editor);
     }
     this._font = new BitmapFont("biosFont", 8);
     Highlights.StartRound();
 }
示例#14
0
        private static void SaveCloudFile(string path)
        {
            if (MonoMain.cloudNoSave || !Steam.IsInitialized())
            {
                return;
            }
            string localSavePath = DuckFile.GetLocalSavePath(path);

            if (localSavePath == null)
            {
                return;
            }
            byte[] data = File.ReadAllBytes(path);
            Steam.FileWrite("nq403216_" + localSavePath, data, data.Length);
        }
示例#15
0
 public static void UploadAllCloudData()
 {
     foreach (string path in DuckFile.GetFilesNoCloud(DuckFile.profileDirectory, so: SearchOption.AllDirectories))
     {
         DuckFile.SaveCloudFile(path);
     }
     foreach (string path in DuckFile.GetFilesNoCloud(DuckFile.levelDirectory, so: SearchOption.AllDirectories))
     {
         DuckFile.SaveCloudFile(path);
     }
     foreach (string path in DuckFile.GetFilesNoCloud(DuckFile.optionsDirectory, so: SearchOption.AllDirectories))
     {
         DuckFile.SaveCloudFile(path);
     }
 }
示例#16
0
        public static string[] GetDirectories(string path, string filter = "*.*")
        {
            path = path.Replace('\\', '/');
            path = path.Trim('/');
            List <string> stringList = new List <string>();

            foreach (string path1 in DuckFile.GetDirectoriesNoCloud(path))
            {
                if (!Path.GetFileName(path1).Contains("._"))
                {
                    stringList.Add(path1);
                }
            }
            return(stringList.ToArray());
        }
示例#17
0
 public static void DeleteFolder(string folder)
 {
     if (!Directory.Exists(folder))
     {
         return;
     }
     foreach (string directory in DuckFile.GetDirectories(folder))
     {
         DuckFile.DeleteFolder(directory);
     }
     foreach (string file in DuckFile.GetFiles(folder))
     {
         DuckFile.Delete(file);
     }
     Directory.Delete(folder);
 }
示例#18
0
        public static void InitializeMods()
        {
            MonoMain.loadMessage = "Loading Mods";
            Mod mod;

            AppDomain.CurrentDomain.AssemblyResolve += (ResolveEventHandler)((s, resolveArgs) => ModLoader._modAssemblyNames.TryGetValue(resolveArgs.Name, out mod) ? mod.configuration.assembly : (Assembly)null);
            ModLoader.AddMod((Mod)(CoreMod.coreMod = new CoreMod()));
            DuckFile.CreatePath(DuckFile.modsDirectory);
            ModLoader.LoadMods(DuckFile.modsDirectory);
            ManagedContent.InitializeContentSet <Thing>(ManagedContent.Things);
            ManagedContent.InitializeContentSet <AmmoType>(ManagedContent.AmmoTypes);
            ManagedContent.InitializeContentSet <DeathCrateSetting>(ManagedContent.DeathCrateSettings);
            ManagedContent.InitializeContentSet <DestroyType>(ManagedContent.DestroyTypes);
            ContentProperties.InitializeBags(ManagedContent.Things.Types);
            ModLoader.PostLoadMods();
        }
示例#19
0
        public static string[] GetFiles(string path, string filter = "*.*")
        {
            List <string> stringList = new List <string>();

            if (!MonoMain.cloudOnly && Directory.Exists(path))
            {
                stringList = DuckFile.GetFilesNoCloud(path, filter, DuckFile._getFilesOption);
                for (int index = 0; index < stringList.Count; ++index)
                {
                    stringList[index] = stringList[index].Replace('\\', '/');
                }
            }
            if (Options.Data.cloud && !MonoMain.disableCloud && Steam.IsInitialized())
            {
                string localSavePath = DuckFile.GetLocalSavePath(path);
                if (localSavePath != null)
                {
                    int count = Steam.FileGetCount();
                    for (int file = 0; file < count; ++file)
                    {
                        string name = Steam.FileGetName(file);
                        int    num  = name.IndexOf(localSavePath);
                        if (num != -1 && name.StartsWith("nq403216_") && num == "nq403216_".Length)
                        {
                            string source = name.Substring(num + localSavePath.Length, name.Length - (num + localSavePath.Length));
                            if (source[0] == '\\' || source[0] == '/')
                            {
                                source = source.Substring(1, source.Length - 1);
                            }
                            if (!source.Contains <char>('/') && !source.Contains <char>('\\') || DuckFile._getFilesOption == SearchOption.AllDirectories)
                            {
                                string str = path;
                                if (!str.EndsWith("/"))
                                {
                                    str += "/";
                                }
                                if (!stringList.Contains(str + source))
                                {
                                    stringList.Add(path + source);
                                }
                            }
                        }
                    }
                }
            }
            return(stringList.ToArray());
        }
示例#20
0
 public static void Initialize()
 {
     DuckFile._saveRoot       = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/";
     DuckFile._saveRoot       = DuckFile._saveRoot.Replace('\\', '/');
     DuckFile._saveDirectory  = "DuckGame/";
     DuckFile._levelDirectory = "Levels/";
     DuckFile._allPaths.Add(DuckFile._levelDirectory);
     DuckFile._onlineLevelDirectory = "Online/Levels/";
     DuckFile._allPaths.Add(DuckFile._onlineLevelDirectory);
     DuckFile._optionsDirectory = "Options/";
     DuckFile._allPaths.Add(DuckFile._optionsDirectory);
     DuckFile._albumDirectory = "Album/";
     DuckFile._allPaths.Add(DuckFile._albumDirectory);
     DuckFile._profileDirectory = "Profiles/";
     DuckFile._allPaths.Add(DuckFile._profileDirectory);
     DuckFile._challengeDirectory = "ChallengeData/";
     DuckFile._allPaths.Add(DuckFile._challengeDirectory);
     DuckFile._modsDirectory = "Mods/";
     DuckFile._allPaths.Add(DuckFile._modsDirectory);
     DuckFile._scriptsDirectory = "Scripts/";
     DuckFile._allPaths.Add(DuckFile._scriptsDirectory);
     DuckFile._workshopDirectory = "Workshop/";
     DuckFile._allPaths.Add(DuckFile._workshopDirectory);
     DuckFile._customBlockDirectory = "Custom/Blocks/";
     DuckFile._allPaths.Add(DuckFile._customBlockDirectory);
     DuckFile.CreatePath(DuckFile.customBlockDirectory);
     DuckFile._downloadedBlockDirectory = "Custom/Blocks/Downloaded/";
     DuckFile._allPaths.Add(DuckFile._downloadedBlockDirectory);
     DuckFile._customBackgroundDirectory = "Custom/Background/";
     DuckFile._allPaths.Add(DuckFile._customBackgroundDirectory);
     DuckFile.CreatePath(DuckFile.customBackgroundDirectory);
     DuckFile._downloadedBackgroundDirectory = "Custom/Background/Downloaded/";
     DuckFile._allPaths.Add(DuckFile._downloadedBackgroundDirectory);
     DuckFile._customPlatformDirectory = "Custom/Platform/";
     DuckFile._allPaths.Add(DuckFile._customPlatformDirectory);
     DuckFile.CreatePath(DuckFile.customPlatformDirectory);
     DuckFile._downloadedPlatformDirectory = "Custom/Platform/Downloaded/";
     DuckFile._allPaths.Add(DuckFile._downloadedPlatformDirectory);
     DuckFile._customParallaxDirectory = "Custom/Parallax/";
     DuckFile._allPaths.Add(DuckFile._customParallaxDirectory);
     DuckFile.CreatePath(DuckFile.customParallaxDirectory);
     DuckFile._downloadedParallaxDirectory = "Custom/Parallax/Downloaded/";
     DuckFile._allPaths.Add(DuckFile._downloadedParallaxDirectory);
     DuckFile._customArcadeDirectory = "Custom/Arcade/";
     DuckFile._allPaths.Add(DuckFile.customArcadeDirectory);
     DuckFile.CreatePath(DuckFile.customArcadeDirectory);
 }
示例#21
0
 public static XDocument LoadXDocument(string path)
 {
     DuckFile.CreatePath(Path.GetDirectoryName(path));
     DuckFile.PrepareToLoadCloudFile(path);
     if (!File.Exists(path))
     {
         return((XDocument)null);
     }
     try
     {
         return(XDocument.Load(path));
     }
     catch
     {
         return((XDocument)null);
     }
 }
示例#22
0
        private static void ProcessLevel(string path, LevelLocation location)
        {
            Main.SpecialCode = "Loading Level " + path != null ? path : "null";
            if (!path.EndsWith(".lev"))
            {
                return;
            }
            path = path.Replace('\\', '/');
            LevelData levelData = DuckFile.LoadLevel(path);

            levelData.SetPath(path);
            path = path.Substring(0, path.Length - 4);
            path.Substring(path.IndexOf("/levels/") + 8);
            bool flag1 = true;

            if (levelData.modData.workshopIDs.Count != 0)
            {
                foreach (ulong workshopId in levelData.modData.workshopIDs)
                {
                    bool flag2 = false;
                    foreach (Mod accessibleMod in (IEnumerable <Mod>)ModLoader.accessibleMods)
                    {
                        if (accessibleMod.configuration != null && (long)accessibleMod.configuration.workshopID == (long)workshopId)
                        {
                            flag2 = true;
                            break;
                        }
                    }
                    if (!flag2)
                    {
                        flag1 = false;
                        break;
                    }
                }
            }
            if (flag1 && !levelData.modData.hasLocalMods)
            {
                RandomLevelDownloader._readyLevels.Add(levelData);
                DevConsole.Log(DCSection.Steam, "Downloaded random level " + RandomLevelDownloader._readyLevels.Count.ToString() + "/" + RandomLevelDownloader.numToHaveReady.ToString());
            }
            else
            {
                DevConsole.Log(DCSection.Steam, "Downloaded level had mods, and was ignored!");
            }
        }
示例#23
0
        public static void Save(string guid)
        {
            if (!Challenges._saveData.ContainsKey(guid))
            {
                return;
            }
            XDocument doc      = new XDocument();
            XElement  xelement = new XElement((XName)"Data");

            foreach (ChallengeSaveData challengeSaveData in Challenges._saveData[guid])
            {
                xelement.Add((object)challengeSaveData.LegacySerialize());
            }
            doc.Add((object)xelement);
            string path = DuckFile.challengeDirectory + guid + ".dat";

            DuckFile.SaveXDocument(doc, path);
        }
示例#24
0
        public static void Delete(string file)
        {
            if (File.Exists(file))
            {
                File.SetAttributes(file, FileAttributes.Normal);
                File.Delete(file);
            }
            if (MonoMain.cloudNoSave || !Steam.IsInitialized())
            {
                return;
            }
            string localSavePath = DuckFile.GetLocalSavePath(file);

            if (localSavePath == null)
            {
                return;
            }
            Steam.FileDelete(localSavePath);
        }
示例#25
0
        public static string GetLevelID(string path, LevelLocation loc = LevelLocation.Content)
        {
            if (!path.EndsWith(".lev"))
            {
                path += ".lev";
            }
            foreach (KeyValuePair <string, List <LevelData> > level in (MultiMap <string, LevelData, List <LevelData> >)DuckGame.Content._levels)
            {
                foreach (LevelData levelData in level.Value)
                {
                    if ((levelData.GetLocation() == loc || loc == LevelLocation.Any) && levelData.GetPath().EndsWith("/" + path))
                    {
                        return(levelData.metaData.guid);
                    }
                }
            }
            LevelData levelData1 = DuckFile.LoadLevel(DuckGame.Content.path + "/levels/" + path + ".lev");

            return(levelData1 != null ? levelData1.metaData.guid : "");
        }
示例#26
0
        public static void SaveChunk(BinaryClassChunk doc, string path)
        {
            DuckFile.CreatePath(Path.GetDirectoryName(path));
            try
            {
                if (File.Exists(path))
                {
                    File.SetAttributes(path, FileAttributes.Normal);
                }
            }
            catch (Exception ex)
            {
            }
            BitBuffer  bitBuffer  = doc.Serialize();
            FileStream fileStream = File.Create(path);

            fileStream.Write(bitBuffer.buffer, 0, bitBuffer.lengthInBytes);
            fileStream.Close();
            DuckFile.SaveCloudFile(path);
        }
示例#27
0
        public static string[] GetFiles(string path, string filter = "*.*")
        {
            path = path.Replace('\\', '/');
            path = path.Trim('/');
            string        str1       = (Directory.GetCurrentDirectory() + "/").Replace('\\', '/');
            List <string> stringList = new List <string>();

            foreach (string path1 in DuckFile.GetFilesNoCloud(path, filter))
            {
                if (!Path.GetFileName(path1).Contains("._"))
                {
                    string str2       = path1.Replace('\\', '/');
                    int    startIndex = str2.IndexOf(str1);
                    if (startIndex != -1)
                    {
                        str2 = str2.Remove(startIndex, str1.Length);
                    }
                    stringList.Add(str2);
                }
            }
            return(stringList.ToArray());
        }
示例#28
0
        public static void SaveXDocument(XDocument doc, string path)
        {
            DuckFile.CreatePath(Path.GetDirectoryName(path));
            try
            {
                if (File.Exists(path))
                {
                    File.SetAttributes(path, FileAttributes.Normal);
                }
            }
            catch (Exception ex)
            {
            }
            string contents = doc.ToString();

            if (string.IsNullOrWhiteSpace(contents))
            {
                throw new Exception("Blank XML (" + path + ")");
            }
            File.WriteAllText(path, contents);
            DuckFile.SaveCloudFile(path);
        }
        private static void ResultFetched(object value0, WorkshopQueryResult result)
        {
            if (result == null || result.details == null)
            {
                return;
            }
            WorkshopItem publishedFile = result.details.publishedFile;

            if (publishedFile == null)
            {
                return;
            }
            try
            {
                if ((publishedFile.stateFlags & WorkshopItemState.Installed) == WorkshopItemState.None || !Directory.Exists(publishedFile.path))
                {
                    return;
                }
                foreach (string folder in DuckFile.GetDirectoriesNoCloud(publishedFile.path))
                {
                    ModConfiguration modConfiguration = ModLoader.AttemptModLoad(folder);
                    if (modConfiguration != null)
                    {
                        try
                        {
                            modConfiguration.isWorkshop = true;
                            ModLoader.loadableMods.Add(modConfiguration.uniqueID, modConfiguration);
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
示例#30
0
        public static string ApplyCustomData(CustomTileData tData, int index, CustomType type)
        {
            string key = tData.path + "@" + (object)tData.checksum + ".png";

            if (tData.texture != null)
            {
                string str = DuckFile.GetCustomDownloadDirectory(type) + key;
                if (!File.Exists(str))
                {
                    DuckFile.CreatePath(str);
                    FileStream fileStream = File.Create(str);
                    tData.texture.SaveAsPng((Stream)fileStream, tData.texture.Width, tData.texture.Height);
                    fileStream.Close();
                }
            }
            else if (tData.path == null)
            {
                return("");
            }
            Custom._customTilesetData[type][key] = tData;
            Custom.data[type][index]             = key;
            return(key);
        }