private void c_btnCreate_Click(object sender, EventArgs e)
        {
            if (c_txtDescription.Text.Length < 20)
            {
                Utility.MessageBoxShow("Description must be atleast 20 characters long");
                return;
            }
            var addonName      = c_txtAddonFolder.Text.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries).Last();
            int addonNameIndex = c_txtAddonFolder.Text.LastIndexOf(addonName);

            string         addonRootFolder = c_txtAddonFolder.Text.Substring(0, addonNameIndex);
            SaveFileDialog saveFileDialog  = new SaveFileDialog();

            saveFileDialog.DefaultExt       = "zip";
            saveFileDialog.Filter           = "Zip files (*.zip)|*.zip|All files (*.*)|*.*";
            saveFileDialog.InitialDirectory = addonRootFolder;
            saveFileDialog.AddExtension     = true;
            saveFileDialog.FileName         = addonName + "Package_" + c_txtVersion.Text + ".zip";
            var dialogResult = saveFileDialog.ShowDialog();

            if (dialogResult == System.Windows.Forms.DialogResult.OK)
            {
                string addonPackageFilename = saveFileDialog.FileName;
                string descFile             = "\r\n#Version=" + c_txtVersion.Text;
                descFile += "\r\n#Description=" + c_txtDescription.Text.Replace("\r\n#", "\n#");
                descFile += "\r\n#UpdateSubmitter=" + Settings.UserID.Split('.').First();
                descFile += "\r\n#UpdateImportance=|DefaultImportance=" + (string)c_cbUpdateImportance.SelectedItem + "|";

                Utility.AssertFilePath(addonPackageFilename);

                ZipFile zipFile;
                if (System.IO.File.Exists(addonPackageFilename) == true)
                {
                    throw new Exception("The AddonPackage file already exists!");
                }

                zipFile = ZipFile.Create(addonPackageFilename);

                zipFile.BeginUpdate();

                zipFile.AddDirectoryFilesRecursive(addonRootFolder, c_txtAddonFolder.Text);

                //ZipEntry descEntry = new ZipEntry(addonName + "/VF_WowLauncher_AddonDescription.txt");
                //descEntry.DateTime = DateTime.Now;

                System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();
                System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(memoryStream);
                streamWriter.Write(descFile);
                streamWriter.Flush();

                CustomStaticDataSource entryDataSource = new CustomStaticDataSource();
                entryDataSource.SetStream(memoryStream);

                zipFile.Add(entryDataSource, addonName + "/VF_WowLauncher_AddonDescription.txt");
                zipFile.CommitUpdate();
                zipFile.Close();
                Close();
            }
        }
Beispiel #2
0
        internal static string BackupAddons(List <string> _AddonNames, WowVersionEnum _WowVersion, AddonBackupMode _BackupMode = AddonBackupMode.BackupWTF_And_AddonFiles)
        {
            int    fileID         = System.Threading.Interlocked.Increment(ref g_UniqueFileIDCounter);
            string backupFileName = StaticValues.LauncherBackupsDirectory + DateTime.Now.ToString("yyyy_MM_dd") + "/BackupAddons_" + DateTime.Now.ToString("HH_mm_ss") + "." + fileID + ".zip";

            Utility.AssertFilePath(backupFileName);

            ZipFile zipFile;

            if (System.IO.File.Exists(backupFileName) == true)
            {
                backupFileName = Utility.ConvertToUniqueFilename(backupFileName, '.');
            }
            if (System.IO.File.Exists(backupFileName) == true)
            {
                throw new Exception("Backup file already exists");
            }

            zipFile = ZipFile.Create(backupFileName);

            zipFile.BeginUpdate();

            foreach (var addonName in _AddonNames)
            {
                if (_BackupMode.HasFlag(AddonBackupMode.BackupWTF))
                {
                    string wtfAccStartPath    = Settings.GetWowDirectory(_WowVersion);
                    var    savedVariableFiles = WowUtility.GetPerCharacterSavedVariableFilePaths(addonName, _WowVersion);
                    savedVariableFiles.AddRange(WowUtility.GetSavedVariableFilePaths(addonName, _WowVersion));

                    foreach (string savedVariableFile in savedVariableFiles)
                    {
                        zipFile.Add(savedVariableFile, savedVariableFile.Substring(wtfAccStartPath.Length));
                    }
                }
                if (_BackupMode.HasFlag(AddonBackupMode.BackupAddonFiles))
                {
                    if (System.IO.Directory.Exists(Settings.GetWowDirectory(_WowVersion) + "Interface\\AddOns\\" + addonName))
                    {
                        zipFile.AddDirectoryFilesRecursive(Settings.GetWowDirectory(_WowVersion), Settings.GetWowDirectory(_WowVersion) + "Interface\\AddOns\\" + addonName);
                    }
                }
            }
            zipFile.CommitUpdate();
            zipFile.Close();
            return(backupFileName);
        }
Beispiel #3
0
 public static void SaveForumSections()
 {
     if (_sm_ForumSections != null)
     {
         lock (_sm_ForumSectionLock)
         {
             bool saveData = false;
             foreach (var forumSection in _sm_ForumSections)
             {
                 if (forumSection.Value.m_DataUpdated == true)
                 {
                     saveData = true;
                 }
                 forumSection.Value.m_DataUpdated = false;
             }
             if (saveData == true)
             {
                 Utility.AssertFilePath(StaticValues.LauncherSettingsDirectory + "DownloadedForumCache.dat");
                 Utility.SaveSerialize(StaticValues.LauncherSettingsDirectory + "DownloadedForumCache.dat", _sm_ForumSections, false);
             }
         }
     }
 }
Beispiel #4
0
        public static string DownloadAddonPackage(string _FTPDownloadAddress, int _AddonPackageFileSize, Action <float> _DownloadProgress = null)
        {
            try
            {
                int fileNameStartIndex = _FTPDownloadAddress.LastIndexOf('\\');
                if (fileNameStartIndex == -1 || fileNameStartIndex < _FTPDownloadAddress.LastIndexOf('/'))
                {
                    fileNameStartIndex = _FTPDownloadAddress.LastIndexOf('/');
                }
                string fileName = StaticValues.LauncherDownloadsDirectory + _FTPDownloadAddress.Substring(fileNameStartIndex + 1);

                FtpWebRequest    ftpRequest  = null;
                FtpWebResponse   ftpResponse = null;
                System.IO.Stream ftpStream   = null;
                /* Create an FTP Request */
                ftpRequest = (FtpWebRequest)FtpWebRequest.Create(_FTPDownloadAddress);
                _DownloadProgress(0.1f);
                /* Log in to the FTP Server with the User Name and Password Provided */
                ftpRequest.Credentials = new NetworkCredential("WowLauncherUpdater", "");
                /* When in doubt, use these options */
                ftpRequest.UseBinary  = true;
                ftpRequest.UsePassive = true;
                ftpRequest.KeepAlive  = true;
                /* Specify the Type of FTP Request */
                ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
                /* Establish Return Communication with the FTP Server */
                ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
                _DownloadProgress(0.2f);
                /* Get the FTP Server's Response Stream */
                ftpStream = ftpResponse.GetResponseStream();
                /* Open a File Stream to Write the Downloaded File */
                Utility.AssertFilePath(fileName);
                System.IO.FileStream localFileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
                _DownloadProgress(0.3f);
                /* Buffer for the Downloaded Data */
                byte[] byteBuffer = new byte[2048];
                int    bytesRead  = ftpStream.Read(byteBuffer, 0, 2048);
                /* Download the File by Writing the Buffered Data Until the Transfer is Complete */
                int totalDownloaded = 0;
                try
                {
                    while (bytesRead > 0)
                    {
                        localFileStream.Write(byteBuffer, 0, bytesRead);
                        totalDownloaded += bytesRead;
                        if (_AddonPackageFileSize != 0)
                        {
                            float progressValue = 0.3f + ((float)totalDownloaded / (float)_AddonPackageFileSize) * 0.65f;
                            if (progressValue <= 0.95f)
                            {
                                _DownloadProgress(progressValue);
                            }
                        }
                        bytesRead = ftpStream.Read(byteBuffer, 0, 2048);
                    }
                }
                catch (Exception ex) { Logger.LogException(ex); }
                /* Resource Cleanup */
                localFileStream.Close();
                ftpStream.Close();
                ftpResponse.Close();
                ftpRequest = null;
                _DownloadProgress(1.0f);
                return(fileName);
            }
            catch (Exception ex) { Logger.LogException(ex); }
            return("");
        }