Exemple #1
0
        /// <summary>
        /// Writes an LDML representation of this writing system to the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        public void WriteLdml(XmlWriter writer)
        {
            var adaptor = new FwLdmlAdaptor();

            lock (m_syncRoot)
                adaptor.Write(writer, this, null);
        }
		/// <summary>
		/// Writes an LDML representation of this writing system to the specified writer.
		/// </summary>
		/// <param name="writer">The writer.</param>
		public void WriteLdml(XmlWriter writer)
		{
			var adaptor = new FwLdmlAdaptor();
			lock (m_syncRoot)
				adaptor.Write(writer, this, null);
		}
		/// <summary>
		/// Adds the writing system to the store or updates the store information about
		/// an already-existing writing system.  Set should be called when there is a change
		/// that updates the RFC5646 information.
		/// </summary>
		public void Set(IWritingSystemDefinition ws)
		{
			m_mutex.WaitOne();
			MemoryStream oldData = null;
			try
			{
				string writingSystemFileName = GetFileName(ws);
				string writingSystemFilePath = GetFilePath(ws);
				if (!ws.Modified && File.Exists(writingSystemFilePath))
					return; // no need to save (better to preserve the modified date)
				var oldId = ws.StoreID;
				string incomingFileName = GetFileName(oldId);
				string incomingFilePath = GetFilePath(oldId);
				if (!string.IsNullOrEmpty(incomingFileName))
				{
					if (File.Exists(incomingFilePath))
					{
						// load old data to preserve stuff in LDML that we don't use, but don't throw up an error if it fails
						try
						{
							oldData = new MemoryStream(File.ReadAllBytes(incomingFilePath), false);
						}
						catch
						{
						}
						if (writingSystemFileName != incomingFileName)
						{
							File.Delete(incomingFilePath);
							// JohnT: Added this without fully understanding, to get things to compile. I don't fully
							// know when this event should be raised, nor am I sure I am building the argument correctly.
							// However, I don't think anything (at least in our code) actually uses it.
							if (WritingSystemIdChanged != null)
								WritingSystemIdChanged(this, new WritingSystemIdChangedEventArgs(oldId, ((PalasoWritingSystem)ws).RFC5646));
						}
					}
				}
				var adaptor = new FwLdmlAdaptor();
				try
				{
					// Provides FW on Linux multi-user access. Overrides the system
					// umask and creates the files with the permissions "775".
					// The "fieldworks" group was created outside the app during
					// configuration of the package which allows group access.
					using (new FileModeOverride())
					{
						adaptor.Write(writingSystemFilePath, (WritingSystemDefinition)ws, oldData);
					}
				}
				catch (UnauthorizedAccessException)
				{
					// If we can't save the changes, too bad. Inability to save locally is typically caught
					// when we go to open the modify dialog. If we can't make the global store consistent,
					// as we well may not be able to in a client-server mode, too bad.
				}

				ws.Modified = false;
			}
			finally
			{
				if (oldData != null)
					oldData.Dispose();
				m_mutex.ReleaseMutex();
			}
		}
Exemple #4
0
        /// <summary>
        /// Adds the writing system to the store or updates the store information about
        /// an already-existing writing system.  Set should be called when there is a change
        /// that updates the RFC5646 information.
        /// </summary>
        public void Set(WritingSystemDefinition ws)
        {
            m_mutex.WaitOne();
            MemoryStream oldData = null;

            try
            {
                string writingSystemFileName = GetFileName(ws);
                string writingSystemFilePath = GetFilePath(ws);
                if (!ws.Modified && File.Exists(writingSystemFilePath))
                {
                    return;                     // no need to save (better to preserve the modified date)
                }
                var    oldId            = ws.StoreID;
                string incomingFileName = GetFileName(oldId);
                string incomingFilePath = GetFilePath(oldId);
                if (!string.IsNullOrEmpty(incomingFileName))
                {
                    if (File.Exists(incomingFilePath))
                    {
                        // load old data to preserve stuff in LDML that we don't use, but don't throw up an error if it fails
                        try
                        {
                            oldData = new MemoryStream(File.ReadAllBytes(incomingFilePath), false);
                        }
                        catch
                        {
                        }
                        if (writingSystemFileName != incomingFileName)
                        {
                            File.Delete(incomingFilePath);
                            // JohnT: Added this without fully understanding, to get things to compile. I don't fully
                            // know when this event should be raised, nor am I sure I am building the argument correctly.
                            // However, I don't think anything (at least in our code) actually uses it.
                            if (WritingSystemIdChanged != null)
                            {
                                WritingSystemIdChanged(this, new WritingSystemIdChangedEventArgs(oldId, ((PalasoWritingSystem)ws).RFC5646));
                            }
                        }
                    }
                }
                var adaptor = new FwLdmlAdaptor();
                try
                {
                    adaptor.Write(writingSystemFilePath, ws, oldData);
                }
                catch (UnauthorizedAccessException)
                {
                    // If we can't save the changes, too bad. Inability to save locally is typically caught
                    // when we go to open the modify dialog. If we can't make the global store consistent,
                    // as we well may not be able to in a client-server mode, too bad.
                }

                ws.Modified = false;
            }
            finally
            {
                if (oldData != null)
                {
                    oldData.Dispose();
                }
                m_mutex.ReleaseMutex();
            }
        }