Skip to content

Commit

Permalink
fix gui build (safe-string)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygrek committed Aug 7, 2024
1 parent ddeaf5c commit b9a1237
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
12 changes: 7 additions & 5 deletions src/gtk2/gui/configWindow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,13 @@ let add_color_param ~p ~top ~(table : GPack.table) ?(h_label : GMisc.label optio
let r = (Gdk.Color.red color) / 256 in
let g = (Gdk.Color.green color) / 256 in
let b = (Gdk.Color.blue color) / 256 in
let s = Printf.sprintf "%02X%02X%02X" r g b in
let _ =
for i = 1 to (String.length s) - 1 do
if s.[i] = ' ' then s.[i] <- '0'
done
let s =
let s = Bytes.unsafe_of_string @@ Printf.sprintf "%02X%02X%02X" r g b in
(* FIXME why start from 1 not 0? also seems this code is not needed, %02X takes care *)
for i = 1 to (Bytes.length s) - 1 do
if Bytes.get s i = ' ' then Bytes.set s i '0'
done;
Bytes.unsafe_to_string s
in
colv := "#" ^ s;
("0x" ^ s ^ "FF")
Expand Down
24 changes: 11 additions & 13 deletions src/gtk2/gui/guiArt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -440,16 +440,18 @@ let _ =
done

let normalize_availability avail =
let len = String.length avail in
let avail = Bytes.of_string avail in
let len = Bytes.length avail in
for i = 0 to (len - 1) do
if !!O.gtk_misc_use_availability_height
then if (int_of_char avail.[i]) > !!O.gtk_misc_availability_max
then avail.[i] <- (char_of_int !!O.gtk_misc_availability_max)
then if (int_of_char @@ Bytes.get avail i) > !!O.gtk_misc_availability_max
then Bytes.set avail i (char_of_int !!O.gtk_misc_availability_max)
else ()
else if (int_of_char avail.[i]) > 1
then avail.[i] <- (char_of_int 1)
else if (int_of_char @@ Bytes.get avail i) > 1
then Bytes.set avail i (char_of_int 1)
else ()
done
done;
Bytes.unsafe_to_string avail

let get_availability_of availability chunks is_file =
let height = 16 in
Expand All @@ -458,11 +460,8 @@ let get_availability_of availability chunks is_file =
| Some chunks -> max 1 (VB.length chunks) in
let avail =
if is_file
then begin
let s = String.copy availability in
normalize_availability s;
s
end else availability
then normalize_availability availability
else availability
in
let key = (avail, chunks, is_file) in
try
Expand Down Expand Up @@ -533,8 +532,7 @@ let clean_avail_bars list =
List.map (fun (avail, chunks, is_file) ->
if is_file
then begin
let s = String.copy avail in
normalize_availability s;
let s = normalize_availability avail in
(s, chunks, is_file)
end else (avail, chunks, is_file)
) list
Expand Down
15 changes: 8 additions & 7 deletions src/gtk2/gui/guiHtml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ let make_request url =
let file_from_url url =
try
if not (Sys.file_exists cache_dir) then Unix.mkdir cache_dir 0o755;
let file = String.copy url in
for i = 0 to String.length file - 1 do
match file.[i] with
let file = Bytes.of_string url in
for i = 0 to Bytes.length file - 1 do
match Bytes.get file i with
'/'
| '?' | '*' | '&' | ':' -> file.[i] <- '_'
| '?' | '*' | '&' | ':' -> Bytes.set file i '_'
| _ -> ()
done;
Filename.concat cache_dir file
Filename.concat cache_dir (Bytes.unsafe_to_string file)
with _ -> ""

(*************************************************************************)
Expand Down Expand Up @@ -522,8 +522,9 @@ let parse_hisohunt_desc stat s file_size found_title found_desc =
let pos = pos + 6 in
let s = String.sub s pos (len - pos) in
let pos = String2.search_from s 0 "<br>" in
let size = String.sub s 0 pos in
size.[pos - 1] <- 'o';
let size = Bytes.unsafe_of_string @@ String.sub s 0 pos in
Bytes.set size (pos - 1) 'o';
let size = Bytes.unsafe_to_string size in
let len = String.length s in
let pos = String2.search_from s 0 "Seeds: " in
let pos = pos + 7 in
Expand Down
35 changes: 17 additions & 18 deletions src/gtk2/gui/guiMisc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -831,42 +831,41 @@ let availability_bar availability chunks b =
Some pixb
end else None

let get_availability_bar_image avail chunks av_max is_file =
let get_availability_bar_image (avail,chunks) av_max is_file =
let avail = Bytes.of_string avail in
(match chunks with
| None ->
for i = 0 to String.length avail - 1 do
avail.[i] <- char_of_int (av_max - 1)
| None ->
for i = 0 to Bytes.length avail - 1 do
Bytes.set avail i (char_of_int (av_max - 1))
done
| Some chunks ->
for i = 0 to String.length avail - 1 do
avail.[i] <-
char_of_int (match VB.get chunks i with
for i = 0 to Bytes.length avail - 1 do
Bytes.set avail i
(char_of_int (match VB.get chunks i with
| VB.State_complete | VB.State_verified ->
av_max
| VB.State_missing ->
let avail_int =
if is_file then int_of_char avail.[i]
else if int_of_char avail.[i] > 48 then 1 else 0
if is_file then int_of_char @@ Bytes.get avail i
else if int_of_char @@ Bytes.get avail i > 48 then 1 else 0
in
min (av_max - 2) avail_int
| VB.State_partial ->
av_max - 1)
av_max - 1))
done);
avail
Bytes.unsafe_to_string avail

let sort_availability_bar (av1, chunks1) (av2, chunks2) is_file =
let s1 = String.copy av1 in
let s2 = String.copy av2 in
let sort_availability_bar a1 a2 is_file =
if !!O.gtk_misc_use_availability_height && is_file
then begin
let av_max = !!O.gtk_misc_availability_max + 2 in
let avail1 = get_availability_bar_image s1 chunks1 av_max is_file in
let avail2 = get_availability_bar_image s2 chunks2 av_max is_file in
let avail1 = get_availability_bar_image a1 av_max is_file in
let avail2 = get_availability_bar_image a2 av_max is_file in
compare avail1 avail2
end else begin
let av_max = 3 in
let avail1 = get_availability_bar_image s1 chunks1 av_max is_file in
let avail2 = get_availability_bar_image s2 chunks2 av_max is_file in
let avail1 = get_availability_bar_image a1 av_max is_file in
let avail2 = get_availability_bar_image a2 av_max is_file in
compare avail1 avail2
end

Expand Down

0 comments on commit b9a1237

Please sign in to comment.