Esempio n. 1
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);
        }
Esempio n. 2
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);
     }
 }
Esempio n. 3
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());
        }
Esempio n. 4
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());
        }
        private static bool AttemptCompile(ModConfiguration config)
        {
            if (config.noCompilation)
            {
                return(false);
            }
            List <string> filesNoCloud = DuckFile.GetFilesNoCloud(config.directory, "*.cs", SearchOption.AllDirectories);

            if (filesNoCloud.Count == 0)
            {
                return(false);
            }
            config.isDynamic = true;
            CRC32 crC32 = new CRC32();

            byte[] numArray = new byte[2048];
            foreach (string path in filesNoCloud)
            {
                using (FileStream fileStream = File.Open(path, FileMode.Open))
                {
                    while (fileStream.Position != fileStream.Length)
                    {
                        int blockLen = fileStream.Read(numArray, 0, numArray.Length);
                        crC32.ProcessBlock(numArray, blockLen);
                    }
                }
            }
            uint num = crC32.Finalize();

            if (!ModLoader.forceRecompilation && File.Exists(config.hashPath))
            {
                if (File.Exists(config.tempAssemblyPath))
                {
                    try
                    {
                        if ((int)BitConverter.ToUInt32(File.ReadAllBytes(config.hashPath), 0) == (int)num)
                        {
                            return(true);
                        }
                    }
                    catch
                    {
                    }
                }
            }
            File.WriteAllBytes(config.hashPath, BitConverter.GetBytes(num));
            if (ModLoader._provider == null)
            {
                ModLoader._provider   = new CSharpCodeProvider();
                ModLoader._parameters = new CompilerParameters(((IEnumerable <Assembly>)AppDomain.CurrentDomain.GetAssemblies()).Select <Assembly, string>((Func <Assembly, string>)(assembly => assembly.Location)).ToArray <string>());
                ModLoader._parameters.GenerateExecutable = ModLoader._parameters.GenerateInMemory = false;
            }
            if (File.Exists(config.buildLogPath))
            {
                File.SetAttributes(config.buildLogPath, FileAttributes.Normal);
                File.Delete(config.buildLogPath);
            }
            ModLoader._parameters.OutputAssembly = config.tempAssemblyPath;
            CompilerResults compilerResults = ModLoader._provider.CompileAssemblyFromFile(ModLoader._parameters, filesNoCloud.ToArray());

            if (compilerResults.Errors.Count == 0)
            {
                return(true);
            }
            File.WriteAllLines(config.buildLogPath, compilerResults.Output.OfType <string>());
            return(false);
        }