Ejemplo n.º 1
0
        private static void RotateCacheFiles([NotNull] FileInfo cacheFile)
        {
            if (cacheFile.Exists)
            {
                double hours = 999.9;
                if (File.Exists(cacheFile.FullName + ".0"))
                {
                    // see when the last rotate was, and only rotate if its been at least an hour since the last save
                    DateTime dt = File.GetLastWriteTime(cacheFile.FullName + ".0");
                    hours = DateTime.Now.Subtract(dt).TotalHours;
                }

                if (hours >= 24.0) // rotate the save file daily
                {
                    for (int i = 8; i >= 0; i--)
                    {
                        string fn = cacheFile.FullName + "." + i;
                        if (File.Exists(fn))
                        {
                            string fn2 = cacheFile.FullName + "." + (i + 1);
                            if (File.Exists(fn2))
                            {
                                File.Delete(fn2);
                            }

                            File.Move(fn, fn2);
                        }
                    }

                    File.Copy(cacheFile.FullName, cacheFile.FullName + ".0");
                }
            }
        }
Ejemplo n.º 2
0
        public async Task TestUpdating()
        {
            var profile   = utils.AddProfile();
            var mod       = utils.AddMod();
            var unchanged = utils.AddModFile(mod, @"Data\scripts\unchanged.pex", 10);
            var deleted   = utils.AddModFile(mod, @"Data\scripts\deleted.pex", 10);
            var modified  = utils.AddModFile(mod, @"Data\scripts\modified.pex", 10);

            utils.Configure();

            utils.AddManualDownload(
                new Dictionary <string, byte[]>
            {
                { "/baz/unchanged.pex", File.ReadAllBytes(unchanged) },
                { "/baz/deleted.pex", File.ReadAllBytes(deleted) },
                { "/baz/modified.pex", File.ReadAllBytes(modified) },
            });

            await CompileAndInstall(profile);

            utils.VerifyInstalledFile(mod, @"Data\scripts\unchanged.pex");
            utils.VerifyInstalledFile(mod, @"Data\scripts\deleted.pex");
            utils.VerifyInstalledFile(mod, @"Data\scripts\modified.pex");

            var unchanged_path = utils.PathOfInstalledFile(mod, @"Data\scripts\unchanged.pex");
            var deleted_path   = utils.PathOfInstalledFile(mod, @"Data\scripts\deleted.pex");
            var modified_path  = utils.PathOfInstalledFile(mod, @"Data\scripts\modified.pex");

            var extra_path = utils.PathOfInstalledFile(mod, @"something_i_made.foo");

            File.WriteAllText(extra_path, "bleh");

            var extra_folder = Path.Combine(Path.GetDirectoryName(utils.PathOfInstalledFile(mod, @"something_i_made.foo")), "folder_i_made");

            Directory.CreateDirectory(extra_folder);

            Assert.IsTrue(Directory.Exists(extra_folder));


            var unchanged_modified = File.GetLastWriteTime(unchanged_path);
            var modified_modified  = File.GetLastWriteTime(modified_path);

            File.WriteAllText(modified_path, "random data");
            File.Delete(deleted_path);

            Assert.IsTrue(File.Exists(extra_path));

            await CompileAndInstall(profile);

            utils.VerifyInstalledFile(mod, @"Data\scripts\unchanged.pex");
            utils.VerifyInstalledFile(mod, @"Data\scripts\deleted.pex");
            utils.VerifyInstalledFile(mod, @"Data\scripts\modified.pex");

            Assert.AreEqual(unchanged_modified, File.GetLastWriteTime(unchanged_path));
            Assert.AreNotEqual(modified_modified, File.GetLastWriteTime(modified_path));
            Assert.IsFalse(File.Exists(extra_path));
            Assert.IsFalse(Directory.Exists(extra_folder));
        }
Ejemplo n.º 3
0
 public override DateTime GetLastWriteTime(string path)
 {
     return(AfsFile.GetLastWriteTime(path));
 }