@@ -1857,12 +1857,25 @@ public static async Task<int> MoveRoutingRule(List<RulesItem> rules, int index,
18571857 /// <returns>0 if successful</returns>
18581858 public static async Task < int > SetDefaultRouting ( Config config , RoutingItem routingItem )
18591859 {
1860- if ( await SQLiteHelper . Instance . TableAsync < RoutingItem > ( ) . Where ( t => t . Id == routingItem . Id ) . CountAsync ( ) > 0 )
1860+ var items = await AppHandler . Instance . RoutingItems ( ) ;
1861+ if ( items . Any ( t => t . Id == routingItem . Id && t . IsActive == true ) )
18611862 {
1862- config . RoutingBasicItem . RoutingIndexId = routingItem . Id ;
1863+ return - 1 ;
18631864 }
18641865
1865- await SaveConfig ( config ) ;
1866+ foreach ( var item in items )
1867+ {
1868+ if ( item . Id == routingItem . Id )
1869+ {
1870+ item . IsActive = true ;
1871+ }
1872+ else
1873+ {
1874+ item . IsActive = false ;
1875+ }
1876+ }
1877+
1878+ await SQLiteHelper . Instance . UpdateAllAsync ( items ) ;
18661879
18671880 return 0 ;
18681881 }
@@ -1875,7 +1888,7 @@ public static async Task<int> SetDefaultRouting(Config config, RoutingItem routi
18751888 /// <returns>The default routing item</returns>
18761889 public static async Task < RoutingItem > GetDefaultRouting ( Config config )
18771890 {
1878- var item = await AppHandler . Instance . GetRoutingItem ( config . RoutingBasicItem . RoutingIndexId ) ;
1891+ var item = await SQLiteHelper . Instance . TableAsync < RoutingItem > ( ) . FirstOrDefaultAsync ( it => it . IsActive == true ) ;
18791892 if ( item is null )
18801893 {
18811894 var item2 = await SQLiteHelper . Instance . TableAsync < RoutingItem > ( ) . FirstOrDefaultAsync ( ) ;
@@ -1983,6 +1996,18 @@ public static async Task<int> InitBuiltinRouting(Config config, bool blImportAdv
19831996
19841997 if ( ! blImportAdvancedRules && items . Count > 0 )
19851998 {
1999+ //migrate
2000+ //TODO Temporary code to be removed later
2001+ if ( config . RoutingBasicItem . RoutingIndexId . IsNotEmpty ( ) )
2002+ {
2003+ var item = items . FirstOrDefault ( t => t . Id == config . RoutingBasicItem . RoutingIndexId ) ;
2004+ if ( item != null )
2005+ {
2006+ await SetDefaultRouting ( config , item ) ;
2007+ }
2008+ config . RoutingBasicItem . RoutingIndexId = string . Empty ;
2009+ }
2010+
19862011 return 0 ;
19872012 }
19882013
0 commit comments