Ejemplo n.º 1
0
        public void GenerateContentFiles(string sourcePath)
        {
            if (Directory.Exists(sourcePath))
            {
                if (File.Exists("content.xml"))
                {
                    File.Delete("content.xml");
                }
                if (File.Exists("content.info.txt"))
                {
                    File.Delete("content.info.txt");
                }
                if (Directory.Exists("content"))
                {
                    Directory.Delete("content", true);
                }
                Directory.CreateDirectory("content");

                string[] directories = Directory.GetDirectories(sourcePath, "*.*", SearchOption.AllDirectories);
                string[] files       = Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories);
                string   xmlPath     = FormLauncher.RootDirectory.CombinePath("content.xml");
                foreach (string directory in directories)
                {
                    Directory.CreateDirectory(directory.Replace(sourcePath, "content/"));
                }
                foreach (string file in files)
                {
                    string filePath = "content/" + file.Replace(sourcePath, string.Empty);
                    File.Copy(file, filePath, true);
                    FileStateInfo fileInfo = new FileStateInfo(filePath);
                    FileList.Add(fileInfo);
                }
                Files = FileList.ToArray();
                using (FileStream fileStream = new FileStream(xmlPath, FileMode.OpenOrCreate))
                {
                    new XmlSerializer(typeof(FileStateInfo[])).Serialize(fileStream, Files);
                    fileStream.Close();
                }
                string[] contents = new string[2]
                {
                    String.Format("GameVersion={0}", Universal.GAME_VERSION),
                    String.Format("ExecutablePath={0}", Universal.EXECUTABLE_PATH)
                };
                File.WriteAllLines(xmlPath.Replace(".xml", ".info.txt"), contents);
            }
        }
Ejemplo n.º 2
0
        private void RequestFile(FileStateInfo file)
        {
            Invoke(new CrossAppDomainDelegate(updateProgressBar.PerformStep));
            string   uriString = UPDATE_URL + file.FileName.Replace('\\', '/');
            string   fileName  = RootDirectory.CombinePath(file.FileName);
            FileInfo fileInfo  = new FileInfo(fileName);

            if (!Directory.Exists(fileInfo.DirectoryName))
            {
                Directory.CreateDirectory(fileInfo.DirectoryName);
            }
            try
            {
                Uri address = new Uri(uriString);
                webClient.DownloadFile(address, fileName);
            }
            catch
            {
                Logger.Log("Failed to download \"" + file.FileName + "\"");
            }
        }