private void ImportLanguagePack() { try { string path = Path.Combine(this.DataDirectory, importedLocale); string sourceFile = Path.Combine(this.DataDirectory, @"en-US\Resources.xml"); string destFile = Path.Combine(path, "Resources.xml"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (!File.Exists(destFile)) { File.Copy(sourceFile, destFile); } ClearTmpDir(); SetStatusBarText("Extracting language pack..."); ZipUtils.Unzip("Tmp", importedFileName); Resources ds = new Resources(); ds.ReadXml(destFile); int count = ImportFiles(importedLocale, ds, this.TmpDirectory, this.TmpDirectory); ds.AcceptChanges(); ds.WriteXml(destFile); DeleteTmpDir(); LoadLocales(); SetCurrentLocale(importedLocale); FinishProgress(); string message = string.Format("{0} record(s) imported successfully.", count); MessageBox.Show(this, message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { if (IsThreadAbortException(ex)) { return; } throw; } }
private void CompileLanguagePack() { try { string locale = this.SelectedLocale; Resources ds = grdResources.DataSource as Resources; DeleteTmpDir(); //create folder structure Hashtable files = new Hashtable(); foreach (Resources.ResourceRow row in ds.Resource.Rows) { if (!files.ContainsKey(row.File)) { files.Add( row.File, Path.Combine(this.TmpDirectory, row.File) ); } } Hashtable folders = new Hashtable(); string fullFolderName; foreach (string file in files.Keys) { fullFolderName = Path.GetDirectoryName((string)files[file]); if (!folders.ContainsKey(fullFolderName)) { folders.Add(fullFolderName, fullFolderName); } } foreach (string folder in folders.Keys) { if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } } //write resources to resx files string fullFileName; ResXResourceWriter writer = null; foreach (string file in files.Keys) { string filter = string.Format("File = '{0}'", file); DataRow[] rows = ds.Resource.Select(filter, "File"); if (rows.Length > 0) { fullFileName = (string)files[file]; fullFileName = string.Format("{0}{1}{2}.{3}{4}", Path.GetDirectoryName(fullFileName), Path.DirectorySeparatorChar, Path.GetFileNameWithoutExtension(fullFileName), locale, Path.GetExtension(fullFileName) ); writer = new ResXResourceWriter(fullFileName); foreach (DataRow row in rows) { if (row["Value"] != DBNull.Value) { writer.AddResource((string)row["Key"], (string)row["Value"]); } } writer.Close(); } } if (!Directory.Exists(LanguagePacksDirectory)) { Directory.CreateDirectory(LanguagePacksDirectory); } //zip lang pack string zipFile = string.Format("SolidCP Language Pack {0} {1}.zip", locale, GetApplicationVersion()); ZipUtils.Zip("Tmp", "LanguagePacks\\" + zipFile); DeleteTmpDir(); FinishProgress(); string message = string.Format("{0} language pack compiled successfully to\n\"{1}\"", cbSupportedLocales.Text, zipFile); MessageBox.Show(this, message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { if (IsThreadAbortException(ex)) { return; } } }