Ejemplo n.º 1
0
 public static void start( MainForm form, List<ListViewItem> elements )
 {
     m_form		= form;
     m_elements	= elements;
     Thread fd	= new Thread( new ThreadStart( thread_factory ) );
     fd.Start();
 }
Ejemplo n.º 2
0
 public static void start( MainForm form )
 {
     m_form		= form;
     m_elements	= null;
     Thread fd	= new Thread( new ThreadStart( thread_factory ) );
     fd.Start();
 }
Ejemplo n.º 3
0
        public static void start_watch( MainForm form )
        {
            if( m_watching ){
                return;
            };

            m_form = form;
            lock( m_form ){
                m_watching	= true;
                m_can_watch	= true;
                m_do_watch	= false;
                m_active	= false;

                (new Thread( new ThreadStart( watchdog_routine ) )).Start();
            };
        }
Ejemplo n.º 4
0
        public static void load_options( MainForm form )
        {
            XmlDocument config = new XmlDocument();

            try{
                config.Load( config_path() );
            }catch( FileNotFoundException ){
                return;
            };

            if( null == config["settings"] ){
                config.AppendChild( config.CreateElement( "settings" ) );
            };

            form.lv_files.Sorting = ( config["settings"].HasAttribute( "sort" ) )? (SortOrder)Convert.ToInt32( config["settings"].GetAttribute( "sort" ) ) : SortOrder.None;
        }
Ejemplo n.º 5
0
        public static bool load( string path, MainForm form )
        {
            try{
                XmlDocument file = new XmlDocument();

                file.Load( path );

                form.t_base_dir.Text = file["project"].Attributes["destination"].Value.ToLower();

                if( '\\' == form.t_base_dir.Text.Last() ){
                    form.t_base_dir.Text = form.t_base_dir.Text.Remove( form.t_base_dir.Text.Length - 1 );
                };

                XmlElement formats	= file["project"]["formats"];
                XmlElement files	= file["project"]["files"];

                foreach( XmlElement fmt in formats.ChildNodes ){
                    form.add_format( fmt.Attributes["name"].Value );
                };

                foreach( XmlElement fd in files.ChildNodes ){
                    if( conv_core.workbench.valid_file( fd.Attributes["file.path"].Value ) ){
                        bool check_crc = fd.HasAttribute( "file.crc" );
                        ListViewItem li = form.lv_files.Items.Add( "" );
                        conv_core.cImageFile fid = new conv_core.cImageFile( fd.Attributes["file.path"].Value );

                        li.ToolTipText	= fid.path.ToLower();
                        li.Name			= Path.GetFileNameWithoutExtension( li.ToolTipText ).ToLower();
                        li.Text			= Path.GetFileName( li.ToolTipText ).ToLower();
                        li.Tag			= fid;
                        fid.enabled		= Convert.ToBoolean( fd.Attributes["file.enabled"].Value );
                        fid.crc			= ( check_crc )? Convert.ToUInt32( fd.Attributes["file.crc"].Value ) : conv_core.workbench.file_crc( fid.path );
                        li.ForeColor	= ( fid.enabled )? MainForm.cell_font_normal : MainForm.cell_font_disabled;
                        li.UseItemStyleForSubItems = false;

                        if( ( null != fd.Attributes["file.format"] ) && Convert.ToBoolean( fd.Attributes["file.format"].Value ) ){
                            //fid.options =
                        };

                        if( check_crc ){
                            fid.new_crc = conv_core.workbench.file_crc( fid.path );
                            if( fid.crc != fid.new_crc ){
                                li.BackColor = MainForm.cell_back_modified;
                            };
                        }else{
                            fid.new_crc = fid.crc;
                            form.t_mod.Enabled = true;
                        };

                        foreach( ColumnHeader hdr in form.m_formats ){
                            XmlElement convert = null;
                            foreach( XmlElement cvt in fd.ChildNodes ){
                                if( hdr.Text == cvt.Attributes["format"].Value ){
                                    convert = cvt;
                                    break;
                                };
                            };

                            conv_core.cFormat fmt = hdr.Tag as conv_core.cFormat;
                            if( null == convert ){
                                ListViewItem.ListViewSubItem lsi	= li.SubItems.Add( li.Name + "." + fmt.ext );
                                lsi.Tag								= new conv_core.cImageFile( form.t_base_dir.Text + "\\" + lsi.Text );
                            }else{
                                string conv_name = convert.Attributes["destination"].Value;
                                if( '\\' == conv_name[0] ){
                                    conv_name = conv_name.Remove( 0, 1 );
                                };

                                ListViewItem.ListViewSubItem lsi	= li.SubItems.Add( conv_name );
                                conv_core.cImageFile img			= new conv_core.cImageFile( form.t_base_dir.Text + "\\" + lsi.Text );
                                lsi.Tag								= img;
                                img.enabled							= Convert.ToBoolean( convert.Attributes["enabled"].Value );
                                lsi.ForeColor						= Color.FromArgb( (int)( ( img.enabled )? 0xFF000000 : 0xFF666666 ) );

                                if( 0 < convert.ChildNodes.Count ){
                                    img.options = fmt.writer_options_desc.create_options();
                                    foreach( XmlElement prop in convert.ChildNodes ){
                                        if( "property" != prop.Name ){
                                            continue;
                                        };

                                        string op_name = prop.Attributes["name"].Value;
                                        if( null != img.options[ op_name ] ){
                                            conv_core.cOption opt = img.options[ op_name ];
                                            switch( img.options.desc[ op_name ].type ){
                                                case conv_core.OptionType.STRING:
                                                    opt.value_str = prop.Attributes["value"].Value;
                                                break;
                                                default:
                                                    opt.value = Convert.ToInt32( prop.Attributes["value"].Value );
                                                break;
                                            };
                                        };
                                    };
                                };
                            };
                        };
                    };
                };

                foreach( ColumnHeader hdr in form.m_formats ){
                    hdr.AutoResize( ColumnHeaderAutoResizeStyle.ColumnContent );
                };

            }catch( Exception ){
                return false;
            };

            return true;
        }
Ejemplo n.º 6
0
        public static bool save( string path, MainForm form )
        {
            try{
                XmlDocument file	= new XmlDocument();
                string base_dir		= form.t_base_dir.Text;

                if( '\\' == base_dir.Last() ){
                    base_dir = base_dir.Remove( base_dir.Length - 1 );
                };

                XmlElement prj = file.AppendChild( file.CreateElement( "project" ) ) as XmlElement;
                prj.SetAttribute( "destination", base_dir );
                base_dir += '\\';

                XmlElement formats = prj.AppendChild( file.CreateElement( "formats" ) ) as XmlElement;
                foreach( ColumnHeader hdr in form.m_formats ){
                    XmlElement format = formats.AppendChild( file.CreateElement( "format" ) ) as XmlElement;
                    format.SetAttribute( "name", hdr.Text );
                };

                XmlElement files = prj.AppendChild( file.CreateElement( "files" ) ) as XmlElement;
                foreach( ListViewItem li in form.lv_files.Items ){
                    conv_core.cImageFile fid = li.Tag as conv_core.cImageFile;
                    XmlElement fd = files.AppendChild( file.CreateElement( "file" ) ) as XmlElement;
                    fd.SetAttribute( "file.path", fid.path );
                    fd.SetAttribute( "file.enabled", Convert.ToString( fid.enabled ) );
                    fd.SetAttribute( "file.format", Convert.ToString( null != fid.options ) );
                    fd.SetAttribute( "file.crc", Convert.ToString( fid.crc ) );

                    if( null != fid.options ){
                        for( int op_id = 0; fid.options.desc.count > op_id; op_id++ ){
                            conv_core.cOptionDesc desc = fid.options.desc[ op_id ];
                            switch( desc.type ){
                                case conv_core.OptionType.STRING:
                                    fd.SetAttribute( "format." + desc.name, fid.options[ desc.id ].value_str );
                                break;
                                default:
                                    fd.SetAttribute( "format." + desc.name, Convert.ToString( fid.options[ desc.id ].value ) );
                                break;
                            };
                        };
                    };

                    foreach( ColumnHeader hdr in form.m_formats ){
                        ListViewItem.ListViewSubItem lsi	= li.SubItems[ hdr.Index ];
                        conv_core.cImageFile img			= lsi.Tag as conv_core.cImageFile;
                        XmlElement conv						= fd.AppendChild( file.CreateElement( "convert" ) ) as XmlElement;

                        string conv_name = conv_core.workbench.relative_path( base_dir, img.path );
                        while( ( '.' == conv_name[0] ) || ( '\\' == conv_name[0] ) ){
                            conv_name = conv_name.Remove( 0, 1 );
                        };

                        conv.SetAttribute( "format", hdr.Text );
                        conv.SetAttribute( "destination", conv_name );
                        conv.SetAttribute( "enabled", Convert.ToString( img.enabled ) );

                        if( null != img.options ){
                            for( int op_id = 0; img.options.desc.count > op_id; op_id++ ){
                                conv_core.cOptionDesc desc	= img.options.desc[ op_id ];
                                string op_name				=  desc.name;

                                XmlElement opt				= conv.AppendChild( file.CreateElement( "property" ) ) as XmlElement;
                                opt.SetAttribute( "name", op_name );

                                switch( desc.type ){
                                    case conv_core.OptionType.STRING:
                                        opt.SetAttribute( "value", img.options[ op_name ].value_str );
                                    break;
                                    default:
                                        opt.SetAttribute( "value", Convert.ToString( img.options[ op_name ].value ) );
                                    break;
                                };
                            };
                        };
                    };
                };

                file.Save( path );
            }catch( Exception ){
                return false;
            };

            return true;
        }
Ejemplo n.º 7
0
        public static void stop_watch()
        {
            lock( m_form ){
                m_do_watch = false;
                m_watching = false;
            };

            lock( m_monitor ){
                Monitor.PulseAll( m_monitor );
            };

            while( m_active ){
                lock( m_exit_watch ){
                    Monitor.Wait( m_exit_watch, 100 );
                };
            };

            m_form = null;
        }
Ejemplo n.º 8
0
        public static bool save_options( MainForm form )
        {
            XmlDocument config = new XmlDocument();

            try{
                config.Load( config_path() );
            }catch( FileNotFoundException ){

            };

            if( null == config["settings"] ){
                config.AppendChild( config.CreateElement( "settings" ) );
            };

            config["settings"].SetAttribute( "sort", Convert.ToString( (int)form.lv_files.Sorting ) );

            config.Save( config_path() );
            return true;
        }
Ejemplo n.º 9
0
        private static void thread_factory()
        {
            m_process = true;
            int items_count = 0;
            int threads_count = Environment.ProcessorCount / 2;
            m_form.Invoke( new Action( () => {
                m_form.b_process.Enabled			= false;
                m_form.b_progress_cancel.Enabled	= true;
                items_count = ( null == m_elements )? m_form.lv_files.Items.Count : m_elements.Count;
            } ) );

            if( ( 2 > ( items_count / Environment.ProcessorCount ) ) || ( 1 > threads_count ) ){
                threads_count = 1;
            };

            for( int proc_id = 0; threads_count > proc_id; proc_id++ ){
                m_threads.Add( new Thread( thread_routine ) );
                m_routines.Add( new List<ListViewItem>() );
            };

            int pool = 0;

            items_count = 0;
            m_form.Invoke( new Action( () => {
                m_form.lv_files.BeginUpdate();

                if( null == m_elements ){
                    foreach( ListViewItem li in m_form.lv_files.Items ){
                        conv_core.cImageFile img = li.Tag as conv_core.cImageFile;
                        if( img.enabled ){
                            img.new_crc		= conv_core.workbench.file_crc( img.path );
                            li.BackColor	= ( img.crc == img.new_crc )? MainForm.cell_back_normal : MainForm.cell_back_modified;
                            foreach( ListViewItem.ListViewSubItem lsi in li.SubItems ){
                                lsi.BackColor = MainForm.cell_back_normal;
                            };

                            m_routines[ pool++ ].Add( li );
                            if( m_routines.Count <= pool ){
                                pool = 0;
                            };

                            items_count++;
                        };
                    };
                }else{
                    foreach( ListViewItem li in m_elements ){
                        conv_core.cImageFile img = li.Tag as conv_core.cImageFile;
                        if( img.enabled ){
                            li.BackColor = ( img.crc == img.new_crc )? MainForm.cell_back_normal : MainForm.cell_back_modified;
                            foreach( ListViewItem.ListViewSubItem lsi in li.SubItems ){
                                lsi.BackColor = MainForm.cell_back_normal;
                            };

                            m_routines[ pool++ ].Add( li );
                            if( m_routines.Count <= pool ){
                                pool = 0;
                            };

                            items_count++;
                        };
                    };
                };

                m_form.lv_files.EndUpdate();
            } ) );

            m_cancel = false;
            for( int id = 0; m_threads.Count > id; id++ ){
                m_threads[ id ].Start( m_routines[ id ] );
            };

            Thread.Sleep( 0 );

            m_form.Invoke( new Action( () => {
                m_form.pb_progress.Visible	= true;
                m_form.pb_progress.Value	= 0;
                m_form.pb_progress.Maximum	= items_count;
            } ) );

            while( !m_cancel ){
                int score = 0;

                foreach( List<ListViewItem> fd in m_routines ){
                    score += fd.Count;
                };

                if( 0 == score ){
                    break;
                };

                Thread.Sleep( 10 );
            };

            m_cancel = true;
            m_form.Invoke( new Action( () => {
                m_form.pb_progress.Visible = false;
            } ) );

            for( int id = 0; m_threads.Count > id; id++ ){
                m_threads[ id ].Join();
                m_routines[ id ].Clear();
            };

            m_routines.Clear();
            m_threads.Clear();

            m_form.Invoke( new Action( () => {
                m_form.b_process.Enabled			= true;
                m_form.b_progress_cancel.Enabled	= false;
            } ) );

            m_process	= false;
            m_form		= null;
        }