コード例 #1
0
ファイル: MainForm.cs プロジェクト: belsrc/Combinify
        /// <summary>
        /// Initializes a new instance of the frmMain class.
        /// </summary>
        public frmMain()
        {
            InitializeComponent();
            this._prj = new Project();
            string[] args = Environment.GetCommandLineArgs();

            // Check if the user dbl-clicked a project file
            // if so, load it
            if( args.Length > 1 ) {
                OpenProject( args[ 1 ] );
                ChangeTitle();

                // I suppose you could technically have a project with no files
                if( lstFiles.Items.Count > 0 ) {
                    ChangeClearEnable( true );
                }
            }
        }
コード例 #2
0
ファイル: FileOp.cs プロジェクト: belsrc/Combinify
        /// <summary>
        /// Writes a project file to the supllied path using the dir and 
        /// list to populate the project file.
        /// </summary>
        /// <param name="project">A Project object to be saved.</param>
        /// <param name="savePath">Path to save the project file.</param>
        public static void WriteProject( string savePath, Project project )
        {
            try {
                // Create a new XDoc
                var xdoc = new XDocument();

                // Create the Project root element with the
                // LastDir child element and the
                // Destination child element
                var proj = new XElement( "Project",
                           new XElement( "LastDir", project.LastDirectory ),
                           new XElement( "Destination", project.DestinationFile )
                    );

                // Create the Files element that will contain the
                // project file list
                var files = new XElement( "Files" );

                // Add the Files children
                foreach( string s in project.CssFiles ) {
                    files.Add( new XElement( "Path", s ) );
                }

                // Add Files to the Project element
                proj.Add( files );

                // Add the whole tree to the document
                xdoc.Add( proj );

                // Save the document
                xdoc.Save( savePath );
            }
            catch( IOException e ) {
                Dialogs.ErrorDialog( e );
            }
        }
コード例 #3
0
ファイル: FileOp.cs プロジェクト: belsrc/Combinify
        /// <summary>
        /// Reads a project file from disks and returns the files to watch.
        /// </summary>
        /// <param name="openPath">The path of the project file.</param>
        /// <returns>A Project object.</returns>
        public static bool ReadProject( out Project project, string openPath )
        {
            if( File.Exists( openPath ) ) {
                try {
                    Project prj = new Project();

                    // Create the XDoc from the file
                    var xdoc = XDocument.Load( openPath );

                    // Get the LastDir value
                    prj.LastDirectory = xdoc.Element( "Project" ).Element( "LastDir" ).Value;

                    // Get the Destination value if newer version else string.Empty
                    // This way it will maintain backward compatibility
                    if( xdoc.Element( "Project" ).Element( "Destination" ) != null ) {
                        prj.DestinationFile = xdoc.Element( "Project" ).Element( "Destination" ).Value;
                    }
                    else {
                        prj.DestinationFile = string.Empty;
                    }

                    // Get the Files descendants
                    var files = xdoc.Element( "Project" ).Descendants( "Files" );
                    var broken = new StringBuilder( "" );

                    // For each of the paths, check if it exists than
                    // add it to the list, otherwise add to the broken string
                    foreach( var f in files.Elements( "Path" ) ) {
                        if( File.Exists( f.Value ) ) {
                            prj.CssFiles.Add( f.Value );
                        }
                        else {
                            broken.Append( f.Value + "\n" );
                        }
                    }

                    // Notify the user that there was broken links
                    if( broken.ToString() != string.Empty ) {
                        MessageBox.Show( "One or more files from the project could not be found\n\n" +
                                            broken.ToString() );
                    }

                    project = prj;
                    return true;
                }
                catch( XmlException e ) {
                    Dialogs.ErrorDialog( e );
                }
            }

            // File doesnt exist
            project = new Project();
            return false;
        }