did some cleanups added get_index_extended to get the ext_index in a

* include/GParted_Core.h,
  src/GParted_Core.cc: did some cleanups
* include/Operation.h,
  src/Operation.cc: added get_index_extended to get the ext_index in a
  uniform way instead of calculating it every time ourselves.
This commit is contained in:
Bart Hakvoort 2005-12-14 01:58:15 +00:00
parent 523bc6a6b4
commit 25db5b2ec0
5 changed files with 31 additions and 12 deletions

View File

@ -1,3 +1,11 @@
2005-12-14 Bart Hakvoort <hakvoort@cvs.gnome.org>
* include/GParted_Core.h,
src/GParted_Core.cc: did some cleanups
* include/Operation.h,
src/Operation.cc: added get_index_extended to get the ext_index in a
uniform way instead of calculating it every time ourselves.
2005-12-13 Bart Hakvoort <hakvoort@cvs.gnome.org>
* src/GParted_Core.cc: check if file is open before using it.

View File

@ -69,7 +69,7 @@ private:
void set_device_partitions( Device & device ) ;
void set_mountpoints( std::vector<Partition> & partitions, bool first_time = true ) ;
void set_used_sectors( std::vector<Partition> & partitions ) ;
void Insert_Unallocated( const Glib::ustring & device_path, std::vector<Partition> & partitions, Sector start, Sector end, bool inside_extended ) ;
void insert_unallocated( const Glib::ustring & device_path, std::vector<Partition> & partitions, Sector start, Sector end, bool inside_extended ) ;
Glib::ustring get_short_path( const Glib::ustring & real_path ) ;
void LP_Set_Used_Sectors( Partition & partition );
Glib::ustring Get_Flags( ) ;

View File

@ -56,6 +56,7 @@ public:
private:
void Insert_Unallocated( std::vector<Partition> & partitions, Sector start, Sector end, bool inside_extended );
int Get_Index_Original( std::vector<Partition> & partitions ) ;
int get_index_extended( const std::vector<Partition> & partitions ) ;
void Apply_Delete_To_Visual( std::vector<Partition> & partitions );
void Apply_Create_To_Visual( std::vector<Partition> & partitions );

View File

@ -270,9 +270,13 @@ void GParted_Core::set_device_partitions( Device & device )
}
if ( EXT_INDEX > -1 )
Insert_Unallocated( device .path, device .device_partitions[ EXT_INDEX ] .logicals, device .device_partitions[ EXT_INDEX ] .sector_start, device .device_partitions[ EXT_INDEX ] .sector_end, true ) ;
insert_unallocated( device .path,
device .device_partitions[ EXT_INDEX ] .logicals,
device .device_partitions[ EXT_INDEX ] .sector_start,
device .device_partitions[ EXT_INDEX ] .sector_end,
true ) ;
Insert_Unallocated( device .path, device .device_partitions, 0, device .length -1, false ) ;
insert_unallocated( device .path, device .device_partitions, 0, device .length -1, false ) ;
}
void GParted_Core::set_mountpoints( std::vector<Partition> & partitions, bool first_time )
@ -367,7 +371,7 @@ void GParted_Core::set_used_sectors( std::vector<Partition> & partitions )
}
}
void GParted_Core::Insert_Unallocated( const Glib::ustring & device_path, std::vector<Partition> & partitions, Sector start, Sector end, bool inside_extended )
void GParted_Core::insert_unallocated( const Glib::ustring & device_path, std::vector<Partition> & partitions, Sector start, Sector end, bool inside_extended )
{
partition_temp .Reset( ) ;
partition_temp .Set_Unallocated( device_path, 0, 0, inside_extended ) ;

View File

@ -208,6 +208,15 @@ int Operation::Get_Index_Original( std::vector<Partition> & partitions )
return -1 ;
}
int Operation::get_index_extended( const std::vector<Partition> & partitions )
{
for ( unsigned int t = 0 ; t < partitions .size() ; t++ )
if ( partitions[ t ] .type == GParted::TYPE_EXTENDED )
return t ;
return -1 ;
}
void Operation::Apply_Delete_To_Visual( std::vector<Partition> & partitions )
{
if ( ! partition_original .inside_extended )
@ -218,12 +227,11 @@ void Operation::Apply_Delete_To_Visual( std::vector<Partition> & partitions )
}
else
{
unsigned int ext = 0 ;
while ( ext < partitions .size( ) && partitions[ ext ] .type != GParted::TYPE_EXTENDED ) ext++ ;
unsigned int ext = get_index_extended( partitions ) ;
partitions[ ext ] .logicals .erase( partitions[ ext ] .logicals .begin( ) + Get_Index_Original( partitions[ ext ] .logicals ) );
//if deleted partition was logical we have to decrease the partitionnumbers of the logicals with higher numbers by one (only if its a real partition)
//if deleted partition was logical we have to decrease the partitionnumbers of the logicals
//with higher numbers by one (only if its a real partition)
if ( partition_original .status != GParted::STAT_NEW )
for ( unsigned int t = 0 ; t < partitions[ ext ] .logicals .size( ) ; t++ )
if ( partitions[ ext ] .logicals[ t ] .partition_number > partition_original .partition_number )
@ -244,8 +252,7 @@ void Operation::Apply_Create_To_Visual( std::vector<Partition> & partitions )
}
else
{
unsigned int ext = 0 ;
while ( ext < partitions .size( ) && partitions[ ext ] .type != GParted::TYPE_EXTENDED ) ext++ ;
unsigned int ext = get_index_extended( partitions ) ;
partitions[ ext ] .logicals[ Get_Index_Original( partitions[ ext ] .logicals ) ] = partition_new ;
Insert_Unallocated( partitions[ ext ] .logicals, partitions[ ext ] .sector_start, partitions[ ext ] .sector_end, true ) ;
@ -270,8 +277,7 @@ void Operation::Apply_Resize_Move_Extended_To_Visual( std::vector<Partition> & p
Insert_Unallocated( partitions, 0, device .length -1, false ) ;
//stuff INSIDE extended partition
ext = 0 ;
while ( ext < partitions .size( ) && partitions[ ext ] .type != GParted::TYPE_EXTENDED ) ext++ ;
ext = get_index_extended( partitions ) ;
if ( partitions[ ext ] .logicals .size( ) && partitions[ ext ] .logicals .front( ) .type == GParted::TYPE_UNALLOCATED )
partitions[ ext ] .logicals .erase( partitions[ ext ] .logicals .begin( ) ) ;