private bool isMatchingFileGroup(FileGroup group)
        {
            foreach (var allowedGroup in _groups)
            {
                if (allowedGroup.GetChecksum(_project) == group.GetChecksum(_project))
                {
                    return(true);
                }
            }

            return(false);
        }
        private void FileGroupSettingsForm_Load(object sender, EventArgs e)
        {
            WinFormsPersistanceHelper.RestoreState(this);
            CenterToParent();

            nameTextBox.Text      = _fileGroup.Name;
            locationTextBox.Text  = _fileGroup.FolderPath != null ? _fileGroup.FolderPath.FullName : null;
            checkSumTextEdit.Text =
                _fileGroup.GetChecksum(
                    MainForm.Current.ProjectFilesControl.Project ?? Project.Empty).ToString(CultureInfo.InvariantCulture);

            parentTextEdit.Text =
                _fileGroup.ProjectFolder == null
                                        ? _fileGroup.Project.Name
                                        : _fileGroup.ProjectFolder.NameIntelli;

            ignoreDuringExportAndImportCheckEdit.Checked = _fileGroup.IgnoreDuringExportAndImport;
        }
        private bool isMatchingFileGroup(FileGroup group)
        {
            foreach (var allowedGroup in _groups)
            {
                if (allowedGroup.GetChecksum(_project) == group.GetChecksum(_project))
                {
                    return true;
                }
            }

            return false;
        }
		private void buttonOK_Click(object sender, EventArgs e)
		{
			_result = null;

			using (new WaitCursor(this, WaitCursorOption.ShortSleep))
			{
				var cultures = getCultures();

				var baseFolderPath = baseFolderTextEdit.Text.Trim();
				var baseFileName = baseFileNameTextEdit.Text.Trim();

				var extension = @"." + extensionComboBoxEdit.Text.Trim('.');

				var created = 0;

				using (new BackgroundWorkerLongProgressGui(
					delegate(object snd, DoWorkEventArgs args)
					{
						try
						{
							var bw = (BackgroundWorker)snd;

							// --
							// First pass, add all in-memory to check for same file group.

							var fg = new FileGroup(_project);

							if (cultures != null)
							{
								foreach (var culture in cultures)
								{
									var fileName =
										_project.IsNeutralLanguage(culture)
											? baseFileName + extension
											: generateFileName(fg, culture);

									fg.Add(new FileInformation(fg)
											{
												File = new ZlpFileInfo(fileName)
											});
								}

								// Look for same entries.
								if (_project.FileGroups.HasFileGroupWithChecksum(
									fg.GetChecksum(_project)))
								{
									throw new MessageBoxException(
										this,
										Resources.SR_ProjectFilesUserControl_AddResourceFilesWithDialog_ExistsInTheProject,
										MessageBoxIcon.Information);
								}
								else
								{
									// --
									// Second pass, add all existing.

									fg = new FileGroup(_project);

									foreach (var culture in cultures)
									{
										if (bw.CancellationPending)
										{
											throw new OperationCanceledException();
										}

										var fileName =
											_project.IsNeutralLanguage(culture)
												? baseFileName + extension
												: generateFileName(fg, culture);

										FileInformation ffi;

										if (_project.IsNeutralLanguage(culture))
										{
											ffi = new FileInformation(fg)
													{
														File = new ZlpFileInfo(ZlpPathHelper.Combine(baseFolderPath, fileName))
													};
											fg.Add(ffi);
										}
										else
										{
											ffi =
												fg.CreateAndAddNewFile(
													baseFolderPath,
													fileName,
													culture.Name);
										}

										// Must create real file.
										ZlpIOHelper.WriteAllText(ffi.File.FullName, Resources.SR_EmptyResourceFile);

										created++;
									}
								}
							}

							if (_projectFolder != null)
							{
								fg.ProjectFolder = _projectFolder;
							}

							_project.FileGroups.Add(fg);
							_project.MarkAsModified();

							_result = fg;

						}
						catch (OperationCanceledException)
						{
							// Ignore.
						}
					},
					Resources.SR_CreateNewFilesForm_Creating,
					BackgroundWorkerLongProgressGui.CancellationMode.Cancelable,
					this))
				{
				}

				// --

				XtraMessageBox.Show(
					this,
					string.Format(
						Resources.SR_CreateNewFilesForm_Finished03,
						created),
					@"Zeta Resource Editor",
					MessageBoxButtons.OK,
					MessageBoxIcon.Information);
			}
		}
Ejemplo n.º 5
0
        // ADDED: adds resources from file Info lists.
        // I have changed a method doAutomaticallyAddResourceFiles to fill file groups.
        // You can use same method if you call this method from there.
        // ATTENTION: LanguageCodeDetection was modified a bit to support variable amount
        // of point in base name. New method GetBaseName(IInheritedSettings settings, string fileName)
        // was added to get same base name FileGroup gets.
        public void DoAutomaticallyAddResourceFilesFromList(
            BackgroundWorker backgroundWorker,
            ProjectFolder parentProjectFolder,
            ref int fileGroupCount,
            ref int fileCount,
            ICollection <ZlpFileInfo> fileList)
        {
            if (backgroundWorker.CancellationPending)
            {
                throw new OperationCanceledException();
            }
            else if (fileList != null && fileList.Count > 0)
            {
                var fileGroups = Project.FileGroups;
                //if (parentProjectFolder != null)
                //{
                //    fileGroups = parentProjectFolder.ChildFileGroups;
                //}
                foreach (var filePath in fileList)
                {
                    if (backgroundWorker.CancellationPending)
                    {
                        throw new OperationCanceledException();
                    }
                    //other algorithm to determine base name to allow multiple points inside name
                    var baseFileName = LanguageCodeDetection.GetBaseName(Project, filePath.Name);

                    var wantAddResourceFile =
                        checkWantAddResourceFile(filePath);

                    if (wantAddResourceFile)
                    {
                        //find right file group

                        var path      = filePath;
                        var fileGroup = fileGroups.Find(
                            g =>
                            string.Compare(g.BaseName, baseFileName, StringComparison.OrdinalIgnoreCase) == 0 &&
                            string.Compare(g.FolderPath.FullName, path.Directory.FullName,
                                           StringComparison.OrdinalIgnoreCase) == 0);

                        if (fileGroup == null)
                        {
                            fileGroup =
                                new FileGroup(Project)
                            {
                                ProjectFolder = parentProjectFolder
                            };

                            // Look for same entries.
                            if (!Project.FileGroups.HasFileGroupWithChecksum(
                                    fileGroup.GetChecksum(Project)))
                            {
                                fileGroups.Add(fileGroup);

                                fileGroupCount++;
                            }
                        }

                        fileGroup.Add(
                            new FileInformation(fileGroup)
                        {
                            File = filePath
                        });

                        fileCount++;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            Result = null;

            using (new WaitCursor(this, WaitCursorOption.ShortSleep))
            {
                var cultures = getCultures();

                var baseFolderPath = baseFolderTextEdit.Text.Trim();
                var baseFileName   = baseFileNameTextEdit.Text.Trim();

                var extension = @"." + extensionComboBoxEdit.Text.Trim('.');

                var created = 0;

                using (new BackgroundWorkerLongProgressGui(
                           delegate(object snd, DoWorkEventArgs args)
                {
                    try
                    {
                        var bw = (BackgroundWorker)snd;

                        // --
                        // First pass, add all in-memory to check for same file group.

                        var fg = new FileGroup(_project);

                        if (cultures != null)
                        {
                            foreach (var culture in cultures)
                            {
                                var fileName =
                                    _project.IsNeutralLanguage(culture)
                                            ? baseFileName + extension
                                            : generateFileName(fg, culture);

                                fg.Add(new FileInformation(fg)
                                {
                                    File = new ZlpFileInfo(fileName)
                                });
                            }

                            // Look for same entries.
                            if (_project.FileGroups.HasFileGroupWithChecksum(
                                    fg.GetChecksum(_project)))
                            {
                                throw new MessageBoxException(
                                    this,
                                    Resources.SR_ProjectFilesUserControl_AddResourceFilesWithDialog_ExistsInTheProject,
                                    MessageBoxIcon.Information);
                            }
                            else
                            {
                                // --
                                // Second pass, add all existing.

                                fg = new FileGroup(_project);

                                foreach (var culture in cultures)
                                {
                                    if (bw.CancellationPending)
                                    {
                                        throw new OperationCanceledException();
                                    }

                                    var fileName =
                                        _project.IsNeutralLanguage(culture)
                                                ? baseFileName + extension
                                                : generateFileName(fg, culture);

                                    FileInformation ffi;

                                    if (_project.IsNeutralLanguage(culture))
                                    {
                                        ffi = new FileInformation(fg)
                                        {
                                            File = new ZlpFileInfo(ZlpPathHelper.Combine(baseFolderPath, fileName))
                                        };
                                        fg.Add(ffi);
                                    }
                                    else
                                    {
                                        ffi =
                                            fg.CreateAndAddNewFile(
                                                baseFolderPath,
                                                fileName);
                                    }

                                    // Must create real file.
                                    ZlpIOHelper.WriteAllText(ffi.File.FullName, Resources.SR_EmptyResourceFile);

                                    created++;
                                }
                            }
                        }

                        if (_projectFolder != null)
                        {
                            fg.ProjectFolder = _projectFolder;
                        }

                        _project.FileGroups.Add(fg);
                        _project.MarkAsModified();

                        Result = fg;
                    }
                    catch (OperationCanceledException)
                    {
                        // Ignore.
                    }
                },
                           Resources.SR_CreateNewFilesForm_Creating,
                           BackgroundWorkerLongProgressGui.CancellationMode.Cancelable,
                           this))
                {
                }

                // --

                XtraMessageBox.Show(
                    this,
                    string.Format(
                        Resources.SR_CreateNewFilesForm_Finished03,
                        created),
                    @"Zeta Resource Editor",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }
        }
		// ADDED: adds resources from file Info lists.
		// I have changed a method doAutomaticallyAddResourceFiles to fill file groups. 
		// You can use same method if you call this method from there. 
		// ATTENTION: LanguageCodeDetection was modified a bit to support variable amount 
		// of point in base name. New method GetBaseName(IInheritedSettings settings, string fileName) 
		// was added to get same base name FileGroup gets.
		public void DoAutomaticallyAddResourceFilesFromList(
			BackgroundWorker backgroundWorker,
			ProjectFolder parentProjectFolder,
			ref int fileGroupCount,
			ref int fileCount,
			ICollection<ZlpFileInfo> fileList)
		{
			if (backgroundWorker.CancellationPending)
			{
				throw new OperationCanceledException();
			}
			else if (fileList != null && fileList.Count > 0)
			{
				var fileGroups = Project.FileGroups;
				//if (parentProjectFolder != null)
				//{
				//    fileGroups = parentProjectFolder.ChildFileGroups;
				//}
				foreach (var filePath in fileList)
				{
					if (backgroundWorker.CancellationPending)
					{
						throw new OperationCanceledException();
					}
					//other algorithm to determine base name to allow multiple points inside name
					var baseFileName = LanguageCodeDetection.GetBaseName(Project, filePath.Name);

					var wantAddResourceFile =
						checkWantAddResourceFile(filePath);

					if (wantAddResourceFile)
					{
						//find right file group

						var path = filePath;
						var fileGroup = fileGroups.Find(
							g =>
							string.Compare(g.BaseName, baseFileName, true) == 0 &&
							string.Compare(g.FolderPath.FullName, path.Directory.FullName, true) == 0);

						if (fileGroup == null)
						{
							fileGroup =
								new FileGroup(Project)
								{
									ProjectFolder = parentProjectFolder
								};

							// Look for same entries.
							if (!Project.FileGroups.HasFileGroupWithChecksum(
								fileGroup.GetChecksum(Project)))
							{
								fileGroups.Add(fileGroup);

								fileGroupCount++;
							}
						}

						fileGroup.Add(
							new FileInformation(fileGroup)
							{
								File = filePath
							});

						fileCount++;
					}
				}
			}
		}
		public void AddExistingResourceFilesWithDialog()
		{
			using (var ofd = new OpenFileDialog())
			{
				ofd.Multiselect = true;
				ofd.Filter = string.Format(@"{0} (*.resx;*.resw)|*.resx;*.resw",
					Resources.SR_MainForm_openToolStripMenuItemClick_ResourceFiles);
				ofd.RestoreDirectory = true;

				var initialDir =
					ConvertHelper.ToString(
						PersistanceHelper.RestoreValue(
							MainForm.UserStorageIntelligent,
							@"filesInitialDir"));
				ofd.InitialDirectory = initialDir;

				if (ofd.ShowDialog(this) == DialogResult.OK)
				{
					PersistanceHelper.SaveValue(
						MainForm.UserStorageIntelligent,
						@"filesInitialDir",
						ZlpPathHelper.GetDirectoryPathNameFromFilePath(ofd.FileName));

					// --

					var fileGroup = new FileGroup(Project);

					foreach (var filePath in ofd.FileNames)
					{
						fileGroup.Add(new FileInformation(fileGroup)
						{
							File = new ZlpFileInfo(filePath)
						});
					}

					// Look for same entries.
					if (Project.FileGroups.HasFileGroupWithChecksum(
						fileGroup.GetChecksum(Project)))
					{
						throw new MessageBoxException(
							this,
							Resources.SR_ProjectFilesUserControl_AddResourceFilesWithDialog_ExistsInTheProject,
							MessageBoxIcon.Information);
					}
					else
					{
						var parentProjectFolder =
							treeView.SelectedNode.Tag as ProjectFolder;

						if (parentProjectFolder != null)
						{
							fileGroup.ProjectFolder = parentProjectFolder;
						}

						Project.FileGroups.Add(fileGroup);
						Project.MarkAsModified();

						var node = addFileGroupToTree(treeView.SelectedNode, fileGroup);

						// --

						sortTree();

						treeView.SelectedNode = node;

						// Immediately open for editing.
						editResourceFiles();

						UpdateUI();
					}
				}
			}
		}